| 1 |
// P1272R4 |
| 2 |
// { dg-do compile { target c++14 } } |
| 3 |
|
| 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; }; |
| 9 |
|
| 10 |
constexpr bool |
| 11 |
f1 () |
| 12 |
{ |
| 13 |
T t = { 1, 2 }; |
| 14 |
S s = __builtin_bit_cast (S, t); |
| 15 |
return s.a[0] == 1; |
| 16 |
} |
| 17 |
|
| 18 |
constexpr bool |
| 19 |
f2 () |
| 20 |
{ |
| 21 |
U u = { 0, 0 }; |
| 22 |
unsigned char a = __builtin_bit_cast (unsigned char, u); |
| 23 |
return true; |
| 24 |
} |
| 25 |
|
| 26 |
constexpr bool |
| 27 |
f3 () |
| 28 |
{ |
| 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" } |
| 32 |
} |
| 33 |
|
| 34 |
constexpr bool |
| 35 |
f4 () |
| 36 |
{ |
| 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" } |
| 40 |
} |
| 41 |
|
| 42 |
constexpr bool |
| 43 |
f5 () |
| 44 |
{ |
| 45 |
W t = { 1, 2 }; |
| 46 |
V s = __builtin_bit_cast (V, t); |
| 47 |
return s.b.a[0] == 1; |
| 48 |
} |
| 49 |
|
| 50 |
constexpr bool |
| 51 |
f6 () |
| 52 |
{ |
| 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" } |
| 56 |
} |
| 57 |
|
| 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" } |