1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
2f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff
3410e3e206b50e0336bd294fa5fb8dfcca3ee1af5Steve Naroffextern int foof() = 1; // expected-error{{illegal initializer (only variables can be initialized)}}
4410e3e206b50e0336bd294fa5fb8dfcca3ee1af5Steve Naroff
56f9f307d527e3451470dd07ae932475f26c6de6eSteve Naroffstatic int x, y, z;
66f9f307d527e3451470dd07ae932475f26c6de6eSteve Naroff
7d8803632d248a360a040ff03eff1162988058036Chris Lattnerstatic int ary[] = { x, y, z }; // expected-error{{initializer element is not a compile-time constant}}
8d8803632d248a360a040ff03eff1162988058036Chris Lattnerint ary2[] = { x, y, z }; // expected-error{{initializer element is not a compile-time constant}}
96f9f307d527e3451470dd07ae932475f26c6de6eSteve Naroff
106f9f307d527e3451470dd07ae932475f26c6de6eSteve Naroffextern int fileScopeExtern[3] = { 1, 3, 5 }; // expected-warning{{'extern' variable has an initializer}}
116f9f307d527e3451470dd07ae932475f26c6de6eSteve Naroff
1208a41901e18aeb91b87d031b93df70374af02564Douglas Gregorstatic long ary3[] = { 1, "abc", 3, 4 }; // expected-warning{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [4]'}}
1338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
14f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroffvoid func() {
15f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff  int x = 1;
16f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff
17410e3e206b50e0336bd294fa5fb8dfcca3ee1af5Steve Naroff  typedef int TInt = 1; // expected-error{{illegal initializer (only variables can be initialized)}}
18410e3e206b50e0336bd294fa5fb8dfcca3ee1af5Steve Naroff
19d35005ece906cca5238d75b031b8db7eac0ac6e1Steve Naroff  int xComputeSize[] = { 1, 3, 5 };
20f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff
2138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  int x3[x] = { 1, 2 }; // expected-error{{variable-sized object may not be initialized}}
22f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff
23759f25237864f3a3cc23eb01f0c0ce6edcc9342dEli Friedman  int x4 = { 1, 2 }; // expected-warning{{excess elements in scalar initializer}}
24f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff
25f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff  int y[4][3] = {
26f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff    { 1, 3, 5 },
27f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff    { 2, 4, 6 },
28f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff    { 3, 5, 7 },
29f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff  };
30f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff
31f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff  int y2[4][3] = {
32f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff    1, 3, 5, 2, 4, 6, 3, 5, 7
33f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff  };
34f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff
35d35005ece906cca5238d75b031b8db7eac0ac6e1Steve Naroff  int y3[4][3] = {
36d35005ece906cca5238d75b031b8db7eac0ac6e1Steve Naroff    { 1, 3, 5 },
37d35005ece906cca5238d75b031b8db7eac0ac6e1Steve Naroff    { 2, 4, 6 },
38d35005ece906cca5238d75b031b8db7eac0ac6e1Steve Naroff    { 3, 5, 7 },
39d35005ece906cca5238d75b031b8db7eac0ac6e1Steve Naroff    { 4, 6, 8 },
407c53ca6e03833adab4465462b7d5c888741b715dDouglas Gregor    { 5 }, // expected-warning{{excess elements in array initializer}}
41d35005ece906cca5238d75b031b8db7eac0ac6e1Steve Naroff  };
42d35005ece906cca5238d75b031b8db7eac0ac6e1Steve Naroff
43f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff  struct threeElements {
44f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff    int a,b,c;
45f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff  } z = { 1 };
46f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff
4708a41901e18aeb91b87d031b93df70374af02564Douglas Gregor  struct threeElements *p = 7; // expected-warning{{incompatible integer to pointer conversion initializing 'struct threeElements *' with an expression of type 'int'}}
486f9f307d527e3451470dd07ae932475f26c6de6eSteve Naroff
496f9f307d527e3451470dd07ae932475f26c6de6eSteve Naroff  extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}}
5038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
51e31b8fb25b458f00e31dcd657c0840e5238e0f05David Blaikie  static long x2[3] = { 1.0,
52e31b8fb25b458f00e31dcd657c0840e5238e0f05David Blaikie                        "abc", // expected-warning{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [4]'}}
53be0ee875d8a91c031a085cbbd73ad9e8dc1aa8ffDavid Blaikie                         5.8 }; // expected-warning {{implicit conversion from 'double' to 'long' changes value from 5.8 to 5}}
54f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff}
55371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff
56371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroffvoid test() {
57371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  int y1[3] = {
580c706c29f20b6fa36759fa41333b9c3ec0bd2969Eli Friedman    { 1, 2, 3 } // expected-warning{{excess elements in scalar initializer}}
59371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  };
60371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  int y3[4][3] = {
61371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 1, 3, 5 },
62371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 2, 4, 6 },
63371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 3, 5, 7 },
64371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 4, 6, 8 },
657c53ca6e03833adab4465462b7d5c888741b715dDouglas Gregor    {  }, // expected-warning{{use of GNU empty initializer extension}} expected-warning{{excess elements in array initializer}}
66371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  };
67371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  int y4[4][3] = {
687c53ca6e03833adab4465462b7d5c888741b715dDouglas Gregor    { 1, 3, 5, 2 }, // expected-warning{{excess elements in array initializer}}
69371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 4, 6 },
70371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 3, 5, 7 },
71a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff    { 4, 6, 8 },
72371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  };
73371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff}
74371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff
75371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroffvoid allLegalAndSynonymous() {
76371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  short q[4][3][2] = {
77371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 1 },
78371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 2, 3 },
79371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 4, 5, 6 }
80371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  };
81371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  short q2[4][3][2] = {
82371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 1, 0, 0, 0, 0, 0 },
83371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 2, 3, 0, 0, 0, 0 },
84371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 4, 5, 6 }
85371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  };
86371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  short q3[4][3][2] = {
87371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    {
88371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff      { 1 },
89371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    },
90371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    {
91371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff      { 2, 3 },
92371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    },
93371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    {
94371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff      { 4, 5 },
95371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff      { 6 },
96371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    },
97371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  };
98371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff}
99371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff
100371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroffvoid legal() {
101371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  short q[][3][2] = {
102371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 1 },
103371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 2, 3 },
104371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 4, 5, 6 }
105371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  };
1064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  int q_sizecheck[(sizeof(q) / sizeof(short [3][2])) == 3? 1 : -1];
107371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff}
108371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff
109fd8b4a4b29a2b9d662d0c9a92c1eebd83160b10bSteve Naroffunsigned char asso_values[] = { 34 };
110fd8b4a4b29a2b9d662d0c9a92c1eebd83160b10bSteve Naroffint legal2() {
111fd8b4a4b29a2b9d662d0c9a92c1eebd83160b10bSteve Naroff  return asso_values[0];
112fd8b4a4b29a2b9d662d0c9a92c1eebd83160b10bSteve Naroff}
113fd8b4a4b29a2b9d662d0c9a92c1eebd83160b10bSteve Naroff
114371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroffvoid illegal() {
115371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  short q2[4][][2] = { // expected-error{{array has incomplete element type 'short [][2]'}}
116371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 1, 0, 0, 0, 0, 0 },
117371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 2, 3, 0, 0, 0, 0 },
118371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    { 4, 5, 6 }
119371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  };
120371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  short q3[4][3][] = { // expected-error{{array has incomplete element type 'short []'}}
121371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    {
122371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff      { 1 },
123371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    },
124371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    {
125371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff      { 2, 3 },
126371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    },
127371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    {
128371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff      { 4, 5 },
129371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff      { 6 },
130371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff    },
131371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  };
132fd89bc825026e44c68a68db72d4012fd6752e70fChris Lattner  int a[][] = { 1, 2 }; // expected-error{{array has incomplete element type 'int []'}}
133371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff}
134371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff
135371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Narofftypedef int AryT[];
136371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff
137371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroffvoid testTypedef()
138371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff{
139371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff  AryT a = { 1, 2 }, b = { 3, 4, 5 };
1404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  int a_sizecheck[(sizeof(a) / sizeof(int)) == 2? 1 : -1];
1414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  int b_sizecheck[(sizeof(b) / sizeof(int)) == 3? 1 : -1];
142371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff}
143371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff
1442fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroffstatic char const xx[] = "test";
1454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregorint xx_sizecheck[(sizeof(xx) / sizeof(char)) == 5? 1 : -1];
1462fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroffstatic char const yy[5] = "test";
1472fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroffstatic char const zz[3] = "test"; // expected-warning{{initializer-string for char array is too long}}
1482fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff
1491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid charArrays() {
1501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static char const test[] = "test";
1511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  int test_sizecheck[(sizeof(test) / sizeof(char)) == 5? 1 : -1];
1521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static char const test2[] = { "weird stuff" };
1531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static char const test3[] = { "test", "excess stuff" }; // expected-warning{{excess elements in char array initializer}}
1542fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff
1552fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff  char* cp[] = { "Hello" };
1562fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff
1572fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff  char c[] = { "Hello" };
1582fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff  int l[sizeof(c) == 6 ? 1 : -1];
1592fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff
16008a41901e18aeb91b87d031b93df70374af02564Douglas Gregor  int i[] = { "Hello "}; // expected-warning{{incompatible pointer to integer conversion initializing 'int' with an expression of type 'char [7]'}}
1617c53ca6e03833adab4465462b7d5c888741b715dDouglas Gregor  char c2[] = { "Hello", "Good bye" }; //expected-warning{{excess elements in char array initializer}}
1622fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff
16308a41901e18aeb91b87d031b93df70374af02564Douglas Gregor  int i2[1] = { "Hello" }; //expected-warning{{incompatible pointer to integer conversion initializing 'int' with an expression of type 'char [6]'}}
1642fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff  char c3[5] = { "Hello" };
1652fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff  char c4[4] = { "Hello" }; //expected-warning{{initializer-string for char array is too long}}
1662fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff
167396f0bfd4b2189452914893ce69f5fb068d0ec22Daniel Dunbar  int i3[] = {}; //expected-warning{{zero size arrays are an extension}} expected-warning{{use of GNU empty initializer extension}}
1682fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff}
1692fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff
170ca107309ffbcacae31d1685ab133f75ca0d7271aSteve Naroffvoid variableArrayInit() {
171ca107309ffbcacae31d1685ab133f75ca0d7271aSteve Naroff  int a = 4;
17273076431605556fdbf28d287d084a73a24a8b8d4John McCall  char strlit[a] = "foo"; //expected-error{{variable-sized object may not be initialized}}
173ca107309ffbcacae31d1685ab133f75ca0d7271aSteve Naroff  int b[a] = { 1, 2, 4 }; //expected-error{{variable-sized object may not be initialized}}
174ca107309ffbcacae31d1685ab133f75ca0d7271aSteve Naroff}
175a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff
176a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff// Pure array tests
177a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Narofffloat r1[10] = {{7}}; //expected-warning{{braces around scalar initializer}}
178a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Narofffloat r2[] = {{8}}; //expected-warning{{braces around scalar initializer}}
179a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffchar r3[][5] = {1,2,3,4,5,6};
1804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregorint r3_sizecheck[(sizeof(r3) / sizeof(char[5])) == 2? 1 : -1];
181a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffchar r3_2[sizeof r3 == 10 ? 1 : -1];
1827c53ca6e03833adab4465462b7d5c888741b715dDouglas Gregorfloat r4[1][2] = {1,{2},3,4}; //expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in array initializer}}
183a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffchar r5[][5] = {"aa", "bbb", "ccccc"};
184a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffchar r6[sizeof r5 == 15 ? 1 : -1];
185a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffconst char r7[] = "zxcv";
186a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffchar r8[5] = "5char";
187a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffchar r9[5] = "6chars"; //expected-warning{{initializer-string for char array is too long}}
188a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff
189a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffint r11[0] = {}; //expected-warning{{zero size arrays are an extension}} expected-warning{{use of GNU empty initializer extension}}
190a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff
191a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff// Some struct tests
192a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffvoid autoStructTest() {
193a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffstruct s1 {char a; char b;} t1;
194a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffstruct s2 {struct s1 c;} t2 = { t1 };
195a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff// The following is a less than great diagnostic (though it's on par with EDG).
19608a41901e18aeb91b87d031b93df70374af02564Douglas Gregorstruct s1 t3[] = {t1, t1, "abc", 0}; //expected-warning{{incompatible pointer to integer conversion initializing 'char' with an expression of type 'char [4]'}}
197a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffint t4[sizeof t3 == 6 ? 1 : -1];
198a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff}
199578edc6614236b224f63ac707acecaeb2a74d6b4Steve Naroffstruct foo { int z; } w;
200578edc6614236b224f63ac707acecaeb2a74d6b4Steve Naroffint bar (void) {
20108a41901e18aeb91b87d031b93df70374af02564Douglas Gregor  struct foo z = { w }; //expected-error{{initializing 'int' with an expression of incompatible type 'struct foo'}}
202578edc6614236b224f63ac707acecaeb2a74d6b4Steve Naroff  return z.z;
203578edc6614236b224f63ac707acecaeb2a74d6b4Steve Naroff}
204a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffstruct s3 {void (*a)(void);} t5 = {autoStructTest};
205a6457963cf7ffe71498c408dd590d9d1acb9513cDouglas Gregorstruct {int a; int b[];} t6 = {1, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}} \
206a6457963cf7ffe71498c408dd590d9d1acb9513cDouglas Gregor// expected-note{{initialized flexible array member 'b' is here}}
207a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffunion {char a; int b;} t7[] = {1, 2, 3};
208a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffint t8[sizeof t7 == (3*sizeof(int)) ? 1 : -1];
209a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff
210a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffstruct bittest{int : 31, a, :21, :12, b;};
2117c53ca6e03833adab4465462b7d5c888741b715dDouglas Gregorstruct bittest bittestvar = {1, 2, 3, 4}; //expected-warning{{excess elements in struct initializer}}
212a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff
213a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff// Not completely sure what should happen here...
214c56c977f44d0bd8422a6f0fe87f361cbb728c06bEli Friedmanint u1 = {}; //expected-warning{{use of GNU empty initializer extension}} expected-error{{scalar initializer cannot be empty}}
21509865a903affa9c08687859d8de65470064c7bc2Eli Friedmanint u2 = {{3}}; //expected-warning{{too many braces around scalar initializer}}
216a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff
217638e14413a4557c399fa2b7da2be5e4e9c1330a2Eli Friedman// PR2362
218638e14413a4557c399fa2b7da2be5e4e9c1330a2Eli Friedmanvoid varArray() {
219638e14413a4557c399fa2b7da2be5e4e9c1330a2Eli Friedman  int c[][x] = { 0 }; //expected-error{{variable-sized object may not be initialized}}
220638e14413a4557c399fa2b7da2be5e4e9c1330a2Eli Friedman}
221402256fc665ba179873ffcb4d630e28cbea42f27Eli Friedman
222402256fc665ba179873ffcb4d630e28cbea42f27Eli Friedman// PR2151
223d7c56e1114bfe7d461786903bb720d2c6efc05a1Richard Smithvoid emptyInit() {struct {} x[] = {6};} //expected-warning{{empty struct is a GNU extension}} \
2240333296d142d45bf2723635848928815b7491f91Douglas Gregor// expected-error{{initializer for aggregate with no elements}}
225402256fc665ba179873ffcb4d630e28cbea42f27Eli Friedman
226d1969d803cfcc65f1c334df4cc89c7fdd33ee4c9Mike Stumpvoid noNamedInit() {
227d1969d803cfcc65f1c334df4cc89c7fdd33ee4c9Mike Stump  struct {int:5;} x[] = {6}; //expected-error{{initializer for aggregate with no elements}}
228f84eda37251c679e2f20343c47a4a3586d9a8e21Eli Friedman}
229f84eda37251c679e2f20343c47a4a3586d9a8e21Eli Friedmanstruct {int a; int:5;} noNamedImplicit[] = {1,2,3};
230f84eda37251c679e2f20343c47a4a3586d9a8e21Eli Friedmanint noNamedImplicitCheck[sizeof(noNamedImplicit) == 3 * sizeof(*noNamedImplicit) ? 1 : -1];
231f84eda37251c679e2f20343c47a4a3586d9a8e21Eli Friedman
23262b6a65f0bef3ada0d8bac1a98f7e0769e6e8ffbNuno Lopes
23362b6a65f0bef3ada0d8bac1a98f7e0769e6e8ffbNuno Lopes// ptrs are constant
23462b6a65f0bef3ada0d8bac1a98f7e0769e6e8ffbNuno Lopesstruct soft_segment_descriptor {
2351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  long ssd_base;
23662b6a65f0bef3ada0d8bac1a98f7e0769e6e8ffbNuno Lopes};
23762b6a65f0bef3ada0d8bac1a98f7e0769e6e8ffbNuno Lopesstatic int dblfault_tss;
23862b6a65f0bef3ada0d8bac1a98f7e0769e6e8ffbNuno Lopes
23962b6a65f0bef3ada0d8bac1a98f7e0769e6e8ffbNuno Lopesunion uniao { int ola; } xpto[1];
24062b6a65f0bef3ada0d8bac1a98f7e0769e6e8ffbNuno Lopes
24162b6a65f0bef3ada0d8bac1a98f7e0769e6e8ffbNuno Lopesstruct soft_segment_descriptor gdt_segs[] = {
2421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  {(long) &dblfault_tss},
2431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  { (long)xpto},
24462b6a65f0bef3ada0d8bac1a98f7e0769e6e8ffbNuno Lopes};
24562b6a65f0bef3ada0d8bac1a98f7e0769e6e8ffbNuno Lopes
24673419bf6cbf8e5f7a0f9b8855d6531db264ae899Nuno Lopesstatic void sppp_ipv6cp_up();
247d7c56e1114bfe7d461786903bb720d2c6efc05a1Richard Smithconst struct {} ipcp = { sppp_ipv6cp_up }; //expected-warning{{empty struct is a GNU extension}} \
2480333296d142d45bf2723635848928815b7491f91Douglas Gregor// expected-warning{{excess elements in struct initializer}}
2494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
250acbabf177079ed41c055b1484465082f9f1d3d06Hans Wennborgstruct _Matrix { union { float m[4][4]; }; }; //expected-warning{{anonymous unions are a C11 extension}}
2514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregortypedef struct _Matrix Matrix;
2524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregorvoid test_matrix() {
2534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  const Matrix mat1 = {
2544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    { { 1.0f, 2.0f, 3.0f, 4.0f,
2554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        5.0f, 6.0f, 7.0f, 8.0f,
2564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        9.0f, 10.0f, 11.0f, 12.0f,
2574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        13.0f, 14.0f, 15.0f, 16.0f } }
2584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  };
2594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
2604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  const Matrix mat2 = {
2614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    1.0f, 2.0f, 3.0f, 4.0f,
2624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    5.0f, 6.0f, 7.0f, 8.0f,
2634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    9.0f, 10.0f, 11.0f, 12.0f,
2644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    13.0f, 14.0f, 15.0f, 16.0f
2654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  };
2664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor}
267e540858b289b23653bcb23646f135729203635cbEli Friedman
268e540858b289b23653bcb23646f135729203635cbEli Friedmanchar badchararray[1] = { badchararray[0], "asdf" }; // expected-warning {{excess elements in array initializer}} expected-error {{initializer element is not a compile-time constant}}
269cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor
270cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor// Test the GNU extension for initializing an array from an array
271cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor// compound literal. PR9261.
272cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregortypedef int int5[5];
273cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregorint a1[5] = (int[]){1, 2, 3, 4, 5}; // expected-warning{{initialization of an array of type 'int [5]' from a compound literal of type 'int [5]' is a GNU extension}}
274cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregorint a2[5] = (int[5]){1, 2, 3, 4, 5}; // expected-warning{{initialization of an array of type 'int [5]' from a compound literal of type 'int [5]' is a GNU extension}}
275cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregorint a3[] = ((int[]){1, 2, 3, 4, 5}); // expected-warning{{initialization of an array of type 'int []' from a compound literal of type 'int [5]' is a GNU extension}}
276cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregorint a4[] = (int[5]){1, 2, 3, 4, 5}; // expected-warning{{initialization of an array of type 'int []' from a compound literal of type 'int [5]' is a GNU extension}}
277cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregorint a5[] = (int5){1, 2, 3, 4, 5}; // expected-warning{{initialization of an array of type 'int []' from a compound literal of type 'int5' (aka 'int [5]') is a GNU extension}}
278cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor
279cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregorint a6[5] = (int[]){1, 2, 3}; // expected-error{{cannot initialize array of type 'int [5]' with array of type 'int [3]'}}
280cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregor
281cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregorint nonconst_value();
282cd9ec3b4fb3d042f89aa5b572de7df3ef9ee4a80Douglas Gregorint a7[5] = (int[5]){ 1, 2, 3, 4, nonconst_value() }; // expected-error{{initializer element is not a compile-time constant}}
28373076431605556fdbf28d287d084a73a24a8b8d4John McCall
28473076431605556fdbf28d287d084a73a24a8b8d4John McCall// <rdar://problem/10636946>
28573076431605556fdbf28d287d084a73a24a8b8d4John McCall__attribute__((weak)) const unsigned int test10_bound = 10;
28673076431605556fdbf28d287d084a73a24a8b8d4John McCallchar test10_global[test10_bound]; // expected-error {{variable length array declaration not allowed at file scope}}
28773076431605556fdbf28d287d084a73a24a8b8d4John McCallvoid test10() {
28873076431605556fdbf28d287d084a73a24a8b8d4John McCall  char test10_local[test10_bound] = "help"; // expected-error {{variable-sized object may not be initialized}}
28973076431605556fdbf28d287d084a73a24a8b8d4John McCall}
290