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