c++: P0847R7 (deducing this) - xobj lambdas. [PR102609]
[official-gcc.git] / gcc / testsuite / g++.dg / cpp2a / bit-cast11.C
blob760c9ca40b4f1b31946ee1a40e3e14eca11a6c45
1 // P1272R4
2 // { dg-do compile { target c++14 } }
4 struct S { unsigned char a[2]; alignas(sizeof 0) int b; };
5 struct T { char a; alignas(sizeof 0) int b; };
6 struct U { char a : 1; char : 6; char b : 1; };
7 struct V { int a; S b; };
8 struct W { unsigned a; T b; };
10 constexpr bool
11 f1 ()
13   T t = { 1, 2 };
14   S s = __builtin_bit_cast (S, t);
15   return s.a[0] == 1;
18 constexpr bool
19 f2 ()
21   U u = { 0, 0 };
22   unsigned char a = __builtin_bit_cast (unsigned char, u);
23   return true;
26 constexpr bool
27 f3 ()
29   T t = { 1, 2 };
30   S s = __builtin_bit_cast (S, t);
31   return s.a[1] == 0;           // { dg-error "accessing uninitialized array element" }
34 constexpr bool
35 f4 ()
37   U u = { 0, 0 };
38   unsigned char a = __builtin_bit_cast (unsigned char, u);
39   return a == 0;                // { dg-error "is not a constant expression" }
42 constexpr bool
43 f5 ()
45   W t = { 1, 2 };
46   V s = __builtin_bit_cast (V, t);
47   return s.b.a[0] == 1;
50 constexpr bool
51 f6 ()
53   W t = { 1, 2 };
54   V s = __builtin_bit_cast (V, t);
55   return s.b.a[1] == 1;         // { dg-error "accessing uninitialized array element" }
58 constexpr bool a = f1 ();
59 constexpr bool b = f2 ();
60 constexpr bool c = f3 ();       // { dg-message "in .constexpr. expansion" }
61 constexpr bool d = f4 ();       // { dg-message "in .constexpr. expansion" }
62 constexpr bool e = f5 ();
63 constexpr bool f = f6 ();       // { dg-message "in .constexpr. expansion" }