array-init.c revision d8803632d248a360a040ff03eff1162988058036
13b427b3ba518f7a7293458c2d3d92eebd8458d87Chris Lattner// RUN: clang -fsyntax-only -verify -pedantic %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 12a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattnerstatic int ary3[] = { 1, "abc", 3, 4 }; // expected-warning{{incompatible pointer to integer conversion initializing 'char [4]', expected 'int'}} 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 23371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff int x4 = { 1, 2 }; // expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in array 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 }, 40d35005ece906cca5238d75b031b8db7eac0ac6e1Steve Naroff { 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 47b7b61159325e002998ff950fdc70a6425a6b13b3Chris Lattner struct threeElements *p = 7; // expected-warning{{incompatible integer to pointer conversion initializing 'int', expected 'struct threeElements *'}} 486f9f307d527e3451470dd07ae932475f26c6de6eSteve Naroff 496f9f307d527e3451470dd07ae932475f26c6de6eSteve Naroff extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}} 5038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff 51a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner static int x2[3] = { 1.0, "abc" , 5.8 }; // expected-warning{{incompatible pointer to integer conversion initializing 'char [4]', expected 'int'}} 52f009063ab7e05be7781751ff9e4b42630f07a747Steve Naroff} 53371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff 54371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroffvoid test() { 55371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff int y1[3] = { 56371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 1, 2, 3 } // expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in array initializer}} 57371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }; 58371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff int y3[4][3] = { 59371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 1, 3, 5 }, 60371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 2, 4, 6 }, 61371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 3, 5, 7 }, 62371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 4, 6, 8 }, 63371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { }, // expected-warning{{use of GNU empty initializer extension}} expected-warning{{excess elements in array initializer}} 64371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }; 65371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff int y4[4][3] = { 66371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 1, 3, 5, 2 }, // expected-warning{{excess elements in array initializer}} 67371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 4, 6 }, 68371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 3, 5, 7 }, 69a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff { 4, 6, 8 }, 70371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }; 71371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff} 72371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff 73371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroffvoid allLegalAndSynonymous() { 74371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff short q[4][3][2] = { 75371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 1 }, 76371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 2, 3 }, 77371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 4, 5, 6 } 78371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }; 79371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff short q2[4][3][2] = { 80371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 1, 0, 0, 0, 0, 0 }, 81371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 2, 3, 0, 0, 0, 0 }, 82371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 4, 5, 6 } 83371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }; 84371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff short q3[4][3][2] = { 85371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 86371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 1 }, 87371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }, 88371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 89371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 2, 3 }, 90371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }, 91371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 92371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 4, 5 }, 93371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 6 }, 94371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }, 95371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }; 96371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff} 97371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff 98371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroffvoid legal() { 99371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff short q[][3][2] = { 100371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 1 }, 101371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 2, 3 }, 102371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 4, 5, 6 } 103371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }; 104371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff} 105371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff 106fd8b4a4b29a2b9d662d0c9a92c1eebd83160b10bSteve Naroffunsigned char asso_values[] = { 34 }; 107fd8b4a4b29a2b9d662d0c9a92c1eebd83160b10bSteve Naroffint legal2() { 108fd8b4a4b29a2b9d662d0c9a92c1eebd83160b10bSteve Naroff return asso_values[0]; 109fd8b4a4b29a2b9d662d0c9a92c1eebd83160b10bSteve Naroff} 110fd8b4a4b29a2b9d662d0c9a92c1eebd83160b10bSteve Naroff 111371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroffvoid illegal() { 112371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff short q2[4][][2] = { // expected-error{{array has incomplete element type 'short [][2]'}} 113371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 1, 0, 0, 0, 0, 0 }, 114371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 2, 3, 0, 0, 0, 0 }, 115371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 4, 5, 6 } 116371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }; 117371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff short q3[4][3][] = { // expected-error{{array has incomplete element type 'short []'}} 118371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 119371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 1 }, 120371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }, 121371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 122371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 2, 3 }, 123371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }, 124371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 125371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 4, 5 }, 126371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff { 6 }, 127371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }, 128371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff }; 129fd89bc825026e44c68a68db72d4012fd6752e70fChris Lattner int a[][] = { 1, 2 }; // expected-error{{array has incomplete element type 'int []'}} 130371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff} 131371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff 132371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Narofftypedef int AryT[]; 133371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff 134371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroffvoid testTypedef() 135371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff{ 136371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff AryT a = { 1, 2 }, b = { 3, 4, 5 }; 137371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff} 138371227d6dc3cf89a3165d592cd9a4cbb400ec45cSteve Naroff 1392fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroffstatic char const xx[] = "test"; 1402fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroffstatic char const yy[5] = "test"; 1412fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroffstatic char const zz[3] = "test"; // expected-warning{{initializer-string for char array is too long}} 1422fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff 1432fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroffvoid charArrays() 1442fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff{ 1452fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff static char const test[] = "test"; 1462fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff static char const test2[] = { "weird stuff" }; 1472fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff static char const test3[] = { "test", "excess stuff" }; // expected-error{{excess elements in char array initializer}} 1482fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff 1492fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff char* cp[] = { "Hello" }; 1502fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff 1512fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff char c[] = { "Hello" }; 1522fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff int l[sizeof(c) == 6 ? 1 : -1]; 1532fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff 154a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner int i[] = { "Hello "}; // expected-warning{{incompatible pointer to integer conversion initializing 'char [7]', expected 'int'}} 1552fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff char c2[] = { "Hello", "Good bye" }; //expected-error{{excess elements in char array initializer}} 1562fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff 157a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner int i2[1] = { "Hello" }; //expected-warning{{incompatible pointer to integer conversion initializing 'char [6]', expected 'int'}} 1582fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff char c3[5] = { "Hello" }; 1592fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff char c4[4] = { "Hello" }; //expected-warning{{initializer-string for char array is too long}} 1602fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff 161fd89bc825026e44c68a68db72d4012fd6752e70fChris Lattner int i3[] = {}; //expected-error{{at least one initializer value required to size array}} expected-warning{{use of GNU empty initializer extension}} 1622fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff} 1632fdc3749097a581567dbd9fe66c48c0458bd3e34Steve Naroff 164ca107309ffbcacae31d1685ab133f75ca0d7271aSteve Naroffvoid variableArrayInit() { 165ca107309ffbcacae31d1685ab133f75ca0d7271aSteve Naroff int a = 4; 166ca107309ffbcacae31d1685ab133f75ca0d7271aSteve Naroff char strlit[a] = "foo"; //expected-error{{variable-sized object may not be initialized}} 167ca107309ffbcacae31d1685ab133f75ca0d7271aSteve Naroff int b[a] = { 1, 2, 4 }; //expected-error{{variable-sized object may not be initialized}} 168ca107309ffbcacae31d1685ab133f75ca0d7271aSteve Naroff} 169a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff 170a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff// Pure array tests 171a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Narofffloat r1[10] = {{7}}; //expected-warning{{braces around scalar initializer}} 172a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Narofffloat r2[] = {{8}}; //expected-warning{{braces around scalar initializer}} 173a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffchar r3[][5] = {1,2,3,4,5,6}; 174a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffchar r3_2[sizeof r3 == 10 ? 1 : -1]; 175a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Narofffloat r4[1][2] = {1,{2},3,4}; //expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in array initializer}} 176a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffchar r5[][5] = {"aa", "bbb", "ccccc"}; 177a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffchar r6[sizeof r5 == 15 ? 1 : -1]; 178a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffconst char r7[] = "zxcv"; 179a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffchar r8[5] = "5char"; 180a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffchar r9[5] = "6chars"; //expected-warning{{initializer-string for char array is too long}} 181a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff 182a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffint r11[0] = {}; //expected-warning{{zero size arrays are an extension}} expected-warning{{use of GNU empty initializer extension}} 183a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff 184a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff// Some struct tests 185a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffvoid autoStructTest() { 186a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffstruct s1 {char a; char b;} t1; 187a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffstruct s2 {struct s1 c;} t2 = { t1 }; 188a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff// The following is a less than great diagnostic (though it's on par with EDG). 189a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattnerstruct s1 t3[] = {t1, t1, "abc", 0}; //expected-warning{{incompatible pointer to integer conversion initializing 'char [4]', expected 'char'}} 190a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffint t4[sizeof t3 == 6 ? 1 : -1]; 191a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff} 192578edc6614236b224f63ac707acecaeb2a74d6b4Steve Naroffstruct foo { int z; } w; 193578edc6614236b224f63ac707acecaeb2a74d6b4Steve Naroffint bar (void) { 194578edc6614236b224f63ac707acecaeb2a74d6b4Steve Naroff struct foo z = { w }; //expected-error{{incompatible type initializing 'struct foo', expected 'int'}} 195578edc6614236b224f63ac707acecaeb2a74d6b4Steve Naroff return z.z; 196578edc6614236b224f63ac707acecaeb2a74d6b4Steve Naroff} 197a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffstruct s3 {void (*a)(void);} t5 = {autoStructTest}; 198a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff// GCC extension; flexible array init. Once this is implemented, the warning should be removed. 199a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff// Note that clang objc implementation depends on this extension. 200a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffstruct {int a; int b[];} t6 = {1, {1, 2, 3}}; //expected-warning{{excess elements in array initializer}} 201a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffunion {char a; int b;} t7[] = {1, 2, 3}; 202a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffint t8[sizeof t7 == (3*sizeof(int)) ? 1 : -1]; 203a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff 204a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffstruct bittest{int : 31, a, :21, :12, b;}; 205a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroffstruct bittest bittestvar = {1, 2, 3, 4}; //expected-warning{{excess elements in array initializer}} 206a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff 207a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff// Not completely sure what should happen here... 208c56c977f44d0bd8422a6f0fe87f361cbb728c06bEli Friedmanint u1 = {}; //expected-warning{{use of GNU empty initializer extension}} expected-error{{scalar initializer cannot be empty}} 209c56c977f44d0bd8422a6f0fe87f361cbb728c06bEli Friedmanint u2 = {{3}}; //expected-error{{too many braces around scalar initializer}} 210a99603333fffb57cf9ac37eabb190c8f5afc914bSteve Naroff 211638e14413a4557c399fa2b7da2be5e4e9c1330a2Eli Friedman// PR2362 212638e14413a4557c399fa2b7da2be5e4e9c1330a2Eli Friedmanvoid varArray() { 213638e14413a4557c399fa2b7da2be5e4e9c1330a2Eli Friedman int c[][x] = { 0 }; //expected-error{{variable-sized object may not be initialized}} 214638e14413a4557c399fa2b7da2be5e4e9c1330a2Eli Friedman} 215402256fc665ba179873ffcb4d630e28cbea42f27Eli Friedman 216402256fc665ba179873ffcb4d630e28cbea42f27Eli Friedman// PR2151 217402256fc665ba179873ffcb4d630e28cbea42f27Eli Friedmanint emptyInit() {struct {} x[] = {6};} //expected-warning{{empty struct extension}} expected-error{{initializer for aggregate with no elements}} 218402256fc665ba179873ffcb4d630e28cbea42f27Eli Friedman 219f84eda37251c679e2f20343c47a4a3586d9a8e21Eli Friedmanint noNamedInit() { 220f84eda37251c679e2f20343c47a4a3586d9a8e21Eli Friedmanstruct {int:5;} x[] = {6}; //expected-error{{initializer for aggregate with no elements}} 221f84eda37251c679e2f20343c47a4a3586d9a8e21Eli Friedman} 222f84eda37251c679e2f20343c47a4a3586d9a8e21Eli Friedmanstruct {int a; int:5;} noNamedImplicit[] = {1,2,3}; 223f84eda37251c679e2f20343c47a4a3586d9a8e21Eli Friedmanint noNamedImplicitCheck[sizeof(noNamedImplicit) == 3 * sizeof(*noNamedImplicit) ? 1 : -1]; 224f84eda37251c679e2f20343c47a4a3586d9a8e21Eli Friedman 225