[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaCXX / builtin-bit-cast.cpp
blob87919d9d9d28656e84311991117d07699059ea8b
1 // RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple x86_64-apple-macosx10.14.0 %s
2 // RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple x86_64-apple-macosx10.14.0 %s -fno-signed-char
4 #if !__has_builtin(__builtin_bit_cast)
5 #error
6 #endif
8 template <class T, T v>
9 T instantiate() {
10 return __builtin_bit_cast(T, v);
13 int x = instantiate<int, 32>();
15 struct secret_ctor {
16 char member;
18 private: secret_ctor() = default;
21 void test1() {
22 secret_ctor c = __builtin_bit_cast(secret_ctor, (char)0);
25 void test2() {
26 constexpr int i = 0;
27 // expected-error@+1{{__builtin_bit_cast source size does not equal destination size (4 vs 1)}}
28 constexpr char c = __builtin_bit_cast(char, i);
31 struct not_trivially_copyable {
32 virtual void foo() {}
35 // expected-error@+1{{__builtin_bit_cast source type must be trivially copyable}}
36 constexpr unsigned long ul = __builtin_bit_cast(unsigned long, not_trivially_copyable{});
38 // expected-error@+1 {{__builtin_bit_cast destination type must be trivially copyable}}
39 constexpr long us = __builtin_bit_cast(unsigned long &, 0L);
41 namespace PR42936 {
42 template <class T> struct S { int m; };
44 extern S<int> extern_decl;
46 int x = __builtin_bit_cast(int, extern_decl);
47 S<char> y = __builtin_bit_cast(S<char>, 0);