| 1 |
// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic -Wno-gnu-folding-constant %s |
| 2 |
// RUN: %clang_cc1 -verify -std=c23 -Wall -pedantic -Wno-gnu-folding-constant %s |
| 3 |
|
| 4 |
/* WG14 N3451: Yes |
| 5 |
* Initialization of anonymous structures and unions |
| 6 |
* |
| 7 |
* This paper allows initialization of anonymous structure and union members |
| 8 |
* within the containing object. |
| 9 |
*/ |
| 10 |
// expected-no-diagnostics |
| 11 |
|
| 12 |
constexpr struct { |
| 13 |
int a : 10; |
| 14 |
int : 12; |
| 15 |
long b; |
| 16 |
} s = { 1, 2 }; |
| 17 |
static_assert(s.a == 1 && s.b == 2); |
| 18 |
|
| 19 |
constexpr union { |
| 20 |
int : 16; |
| 21 |
char c; |
| 22 |
} u = {3}; |
| 23 |
static_assert(u.c == 3); |
| 24 |
|
| 25 |
constexpr struct { |
| 26 |
union { |
| 27 |
float a; |
| 28 |
int b; |
| 29 |
void *p; |
| 30 |
}; |
| 31 |
char c; |
| 32 |
} t = {{.b = 1}, 2}; |
| 33 |
static_assert(t.b == 1 && t.c == 2); |
| 34 |
|
| 35 |
constexpr struct { |
| 36 |
union { |
| 37 |
float a; |
| 38 |
int b; |
| 39 |
void *p; |
| 40 |
}; |
| 41 |
char c; |
| 42 |
} v = {.b = 1, 2}; |
| 43 |
static_assert(v.b == 1 && v.c == 2); |