Skip to content

Commit 51850db

Browse files
committed
[C2y] Claim conformance to WG14 N3451
This paper allows initialization of anonymous structures and unions via braced initializers, which is something Clang has supported since forever.
1 parent 8f02936 commit 51850db

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

clang/test/C/C2y/n3451.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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);

clang/www/c_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ <h2 id="c2y">C2y implementation status</h2>
279279
<tr>
280280
<td>Initialization of anonymous structures and unions</td>
281281
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3451.pdf">N3451</a></td>
282-
<td class="unknown" align="center">Unknown</td>
282+
<td class="full" align="center">Yes</td>
283283
</tr>
284284
<tr>
285285
<td>Slay Some Earthly Demons X</td>

0 commit comments

Comments
 (0)