brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 8717371 Raw
49 lines · cpp
1// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple x86_64-apple-macosx10.14.0 %s2// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple x86_64-apple-macosx10.14.0 %s -fno-signed-char3 4#if !__has_builtin(__builtin_bit_cast)5#error6#endif7 8template <class T, T v>9T instantiate() {10  return __builtin_bit_cast(T, v);11}12 13int x = instantiate<int, 32>();14 15struct secret_ctor {16  char member;17 18private: secret_ctor() = default;19};20 21void test1() {22  secret_ctor c = __builtin_bit_cast(secret_ctor, (char)0);23}24 25void test2() {26  constexpr int i = 0;27  // expected-error@+1{{size of '__builtin_bit_cast' source type 'const int' does not match destination type 'char' (4 vs 1 bytes)}}28  constexpr char c = __builtin_bit_cast(char, i);29}30 31struct not_trivially_copyable {32  virtual void foo() {}33};34 35// expected-error@+1{{'__builtin_bit_cast' source type must be trivially copyable}}36constexpr unsigned long ul = __builtin_bit_cast(unsigned long, not_trivially_copyable{});37 38// expected-error@+1 {{'__builtin_bit_cast' destination type must be trivially copyable}}39constexpr long us = __builtin_bit_cast(unsigned long &, 0L);40 41namespace PR42936 {42template <class T> struct S { int m; };43 44extern S<int> extern_decl;45 46int x = __builtin_bit_cast(int, extern_decl);47S<char> y = __builtin_bit_cast(S<char>, 0);48}49