1 // RUN: clang-cc -fsyntax-only -pedantic -verify %s
2 // C++ [dcl.init.aggr]p2
9 } a1 = { 1, { 2, 3 } };
16 NonAggregate non_aggregate_test = { 1, 2 }; // expected-error{{initialization of non-aggregate type 'struct NonAggregate' with an initializer list}}
18 NonAggregate non_aggregate_test2[2] = { { 1, 2 }, { 3, 4 } }; // expected-error 2 {{initialization of non-aggregate type 'struct NonAggregate' with an initializer list}}
21 // C++ [dcl.init.aggr]p3
24 // C++ [dcl.init.aggr]p4
25 int x[] = { 1, 3, 5 };
26 int x_sizecheck[(sizeof(x) / sizeof(int)) == 3? 1 : -1];
27 int x2[] = { }; // expected-warning{{zero size arrays are an extension}}
29 // C++ [dcl.init.aggr]p5
30 struct StaticMemberTest {
34 } smt = { 1, &smt.i };
36 // C++ [dcl.init.aggr]p6
37 char cv[4] = { 'a', 's', 'd', 'f', 0 }; // expected-error{{excess elements in array initializer}}
39 // C++ [dcl.init.aggr]p7
40 struct TooFew { int a; char* b; int c; };
41 TooFew too_few = { 1, "asdf" }; // okay
43 struct NoDefaultConstructor { // expected-note 3 {{candidate function}}
44 NoDefaultConstructor(int); // expected-note 3 {{candidate function}}
48 NoDefaultConstructor nodef;
50 TooFewError too_few_okay = { 1, 1 };
51 TooFewError too_few_error = { 1 }; // expected-error{{no matching constructor}}
53 TooFewError too_few_okay2[2] = { 1, 1 };
54 TooFewError too_few_error2[2] = { 1 }; // expected-error{{no matching constructor}}
56 NoDefaultConstructor too_few_error3[3] = { }; // expected-error {{no matching constructor}}
58 // C++ [dcl.init.aggr]p8
63 } empty_test = { { }, 3 };
65 EmptyTest empty_test2 = { 3 }; // expected-error{{initializer for aggregate with no elements requires explicit braces}}
73 } non_empty_test = { { }, { } };
75 // C++ [dcl.init.aggr]p9
78 int &j; // expected-note{{uninitialized reference member is here}}
81 HasReference r1 = { 1, global_int };
82 HasReference r2 = { 1 } ; // expected-error{{initialization leaves reference member of type 'int &' uninitialized}}
84 // C++ [dcl.init.aggr]p10
85 // Note: the behavior here is identical to C
86 int xs[2][2] = { 3, 1, 4, 2 };
87 float y[4][3] = { { 1 }, { 2 }, { 3 }, { 4 } };
89 // C++ [dcl.init.aggr]p11
90 // Note: the behavior here is identical to C
91 float y2[4][3] = { { 1, 3, 5 }, { 2, 4, 6 }, { 3, 5, 7 } };
92 float same_as_y2[4][3] = { 1, 3, 5, 2, 4, 6, 3, 5, 7 };
94 // C++ [dcl.init.aggr]p12
112 B2 b2 = { 4, a2, a2 };
113 B2 b2_2 = { 4, d2, 0 };
114 B2 b2_3 = { c2, a2, a2 };
116 // C++ [dcl.init.aggr]p15:
117 union u { int a; char* b; };
120 u u3 = 1; // expected-error{{cannot initialize 'u3' with an rvalue of type 'int'}}
121 u u4 = { 0, "asdf" }; // expected-error{{excess elements in union initializer}}
122 u u5 = { "asdf" }; // expected-error{{incompatible type initializing 'char const [5]', expected 'int'}}