@@ -9,6 +9,7 @@ union U1 { int a; double b; }; // expected-note {{previous definition is here}}
99enum E1 { FOO , BAR }; // expected-note {{previous definition is here}}
1010
1111auto normal_struct = (struct S1 ){ 1 , 2 };
12+ auto normal_struct2 = (struct S1 ) { .x = 1 , .y = 2 };
1213auto underspecified_struct = (struct S2 { int x , y ; }){ 1 , 2 }; // expected-error {{'struct S2' is defined as an underspecified object initializer}}
1314auto underspecified_struct_redef = (struct S1 { char x , y ; }){ 'A' , 'B' }; // expected-error {{redefinition of 'S1'}}
1415auto underspecified_empty_struct = (struct S3 { }){ }; // expected-error {{'struct S3' is defined as an underspecified object initializer}}
@@ -25,3 +26,31 @@ auto underspecified_enum = (enum E2 { BAZ, QUX }){ BAZ }; // expected-erro
2526auto underspecified_enum_redef = (enum E1 { ONE , TWO }){ ONE }; // expected-error {{redefinition of 'E1'}}
2627auto underspecified_empty_enum = (enum E3 { }){ }; // expected-error {{'enum E3' is defined as an underspecified object initializer}} \
2728 expected-error {{use of empty enum}}
29+
30+ // Constexpr tests
31+ constexpr auto ce_struct = (struct S1 ){ 1 , 2 };
32+ constexpr auto ce_union = (union U1 ){ .a = 12 };
33+ constexpr auto ce_enum = (enum E1 ){ FOO };
34+
35+ int func () {
36+ struct S { int x , y ; };
37+ constexpr int i = (struct T { int a , b ; }){0 , 1 }.a ;
38+
39+ struct T t = { 1 , 2 };
40+ }
41+
42+ void func2 () {
43+ int x = (struct Foo { int x ; }){ 0 }.x ;
44+ }
45+
46+ void func3 () {
47+ constexpr int x = (struct Foo { int x ; }){ 0 }.x ;
48+ }
49+
50+ void test () {
51+ constexpr typeof (struct s * ) x = 0 ; // declares `s` which is not an ordinary identifier
52+ constexpr struct S { int a , b ; } y = { 0 }; // declares `S`, `a`, and `b`, none of which are ordinary identifiers
53+ constexpr int a = 0 , b = 0 ; // declares `a` and `b` as ordinary identifiers
54+ auto c = (struct T { int x , y ; }){0 , 0 }; // declares `T`, `x`, and `y`, none of which are ordinary identifiers
55+ constexpr int (* fp )(struct X { int x ; } val ) = 0 ; // declares `X` and `x` which are not ordinary identifiers
56+ }
0 commit comments