| 1 |
// { dg-do compile { target c++14 } } |
| 2 |
|
| 3 |
// this type is not value-initialisable |
| 4 |
struct S { const int a; int b; }; |
| 5 |
|
| 6 |
union U1 { int k; S s; }; |
| 7 |
constexpr int test1() { |
| 8 |
U1 u {}; |
| 9 |
return u.s.b; // { dg-error "accessing .U1::s. member instead of initialized .U1::k. member" } |
| 10 |
} |
| 11 |
constexpr int x = test1(); |
| 12 |
|
| 13 |
union U2 { int :0; static int s; void foo(); int k; }; |
| 14 |
constexpr int test2() { |
| 15 |
U2 u {}; // should skip zero-width bitfields, static members, and functions |
| 16 |
return u.k; |
| 17 |
} |
| 18 |
static_assert(test2() == 0, ""); |