Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s |
Steve Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 2 | |
Steve Naroff | 410e3e2 | 2007-09-12 20:13:48 +0000 | [diff] [blame] | 3 | extern int foof() = 1; // expected-error{{illegal initializer (only variables can be initialized)}} |
| 4 | |
Steve Naroff | 6f9f307 | 2007-09-02 15:34:30 +0000 | [diff] [blame] | 5 | static int x, y, z; |
| 6 | |
Chris Lattner | d880363 | 2008-08-10 01:58:45 +0000 | [diff] [blame] | 7 | static int ary[] = { x, y, z }; // expected-error{{initializer element is not a compile-time constant}} |
| 8 | int ary2[] = { x, y, z }; // expected-error{{initializer element is not a compile-time constant}} |
Steve Naroff | 6f9f307 | 2007-09-02 15:34:30 +0000 | [diff] [blame] | 9 | |
| 10 | extern int fileScopeExtern[3] = { 1, 3, 5 }; // expected-warning{{'extern' variable has an initializer}} |
| 11 | |
Douglas Gregor | 08a4190 | 2010-04-09 17:53:29 +0000 | [diff] [blame] | 12 | static long ary3[] = { 1, "abc", 3, 4 }; // expected-warning{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [4]'}} |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 13 | |
Steve Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 14 | void func() { |
| 15 | int x = 1; |
| 16 | |
Steve Naroff | 410e3e2 | 2007-09-12 20:13:48 +0000 | [diff] [blame] | 17 | typedef int TInt = 1; // expected-error{{illegal initializer (only variables can be initialized)}} |
| 18 | |
Steve Naroff | d35005e | 2007-09-03 01:24:23 +0000 | [diff] [blame] | 19 | int xComputeSize[] = { 1, 3, 5 }; |
Steve Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 20 | |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 21 | int x3[x] = { 1, 2 }; // expected-error{{variable-sized object may not be initialized}} |
Steve Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 22 | |
Eli Friedman | 759f252 | 2009-05-16 11:45:48 +0000 | [diff] [blame] | 23 | int x4 = { 1, 2 }; // expected-warning{{excess elements in scalar initializer}} |
Steve Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 24 | |
| 25 | int y[4][3] = { |
| 26 | { 1, 3, 5 }, |
| 27 | { 2, 4, 6 }, |
| 28 | { 3, 5, 7 }, |
| 29 | }; |
| 30 | |
| 31 | int y2[4][3] = { |
| 32 | 1, 3, 5, 2, 4, 6, 3, 5, 7 |
| 33 | }; |
| 34 | |
Steve Naroff | d35005e | 2007-09-03 01:24:23 +0000 | [diff] [blame] | 35 | int y3[4][3] = { |
| 36 | { 1, 3, 5 }, |
| 37 | { 2, 4, 6 }, |
| 38 | { 3, 5, 7 }, |
| 39 | { 4, 6, 8 }, |
Douglas Gregor | 7c53ca6 | 2009-02-18 22:23:55 +0000 | [diff] [blame] | 40 | { 5 }, // expected-warning{{excess elements in array initializer}} |
Steve Naroff | d35005e | 2007-09-03 01:24:23 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
Steve Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 43 | struct threeElements { |
| 44 | int a,b,c; |
| 45 | } z = { 1 }; |
| 46 | |
Douglas Gregor | 08a4190 | 2010-04-09 17:53:29 +0000 | [diff] [blame] | 47 | struct threeElements *p = 7; // expected-warning{{incompatible integer to pointer conversion initializing 'struct threeElements *' with an expression of type 'int'}} |
Steve Naroff | 6f9f307 | 2007-09-02 15:34:30 +0000 | [diff] [blame] | 48 | |
| 49 | extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}} |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 50 | |
David Blaikie | e31b8fb | 2012-04-05 00:16:44 +0000 | [diff] [blame^] | 51 | static long x2[3] = { 1.0, |
| 52 | "abc", // expected-warning{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [4]'}} |
| 53 | 5.8 }; // expected-warning {{implicit conversion turns literal floating-point number into integer}} |
Steve Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 54 | } |
Steve Naroff | 371227d | 2007-09-04 02:20:04 +0000 | [diff] [blame] | 55 | |
| 56 | void test() { |
| 57 | int y1[3] = { |
Eli Friedman | 0c706c2 | 2011-09-19 23:17:44 +0000 | [diff] [blame] | 58 | { 1, 2, 3 } // expected-warning{{excess elements in scalar initializer}} |
Steve Naroff | 371227d | 2007-09-04 02:20:04 +0000 | [diff] [blame] | 59 | }; |
| 60 | int y3[4][3] = { |
| 61 | { 1, 3, 5 }, |
| 62 | { 2, 4, 6 }, |
| 63 | { 3, 5, 7 }, |
| 64 | { 4, 6, 8 }, |
Douglas Gregor | 7c53ca6 | 2009-02-18 22:23:55 +0000 | [diff] [blame] | 65 | { }, // expected-warning{{use of GNU empty initializer extension}} expected-warning{{excess elements in array initializer}} |
Steve Naroff | 371227d | 2007-09-04 02:20:04 +0000 | [diff] [blame] | 66 | }; |
| 67 | int y4[4][3] = { |
Douglas Gregor | 7c53ca6 | 2009-02-18 22:23:55 +0000 | [diff] [blame] | 68 | { 1, 3, 5, 2 }, // expected-warning{{excess elements in array initializer}} |
Steve Naroff | 371227d | 2007-09-04 02:20:04 +0000 | [diff] [blame] | 69 | { 4, 6 }, |
| 70 | { 3, 5, 7 }, |
Steve Naroff | a996033 | 2008-01-25 00:51:06 +0000 | [diff] [blame] | 71 | { 4, 6, 8 }, |
Steve Naroff | 371227d | 2007-09-04 02:20:04 +0000 | [diff] [blame] | 72 | }; |
| 73 | } |
| 74 | |
| 75 | void allLegalAndSynonymous() { |
| 76 | short q[4][3][2] = { |
| 77 | { 1 }, |
| 78 | { 2, 3 }, |
| 79 | { 4, 5, 6 } |
| 80 | }; |
| 81 | short q2[4][3][2] = { |
| 82 | { 1, 0, 0, 0, 0, 0 }, |
| 83 | { 2, 3, 0, 0, 0, 0 }, |
| 84 | { 4, 5, 6 } |
| 85 | }; |
| 86 | short q3[4][3][2] = { |
| 87 | { |
| 88 | { 1 }, |
| 89 | }, |
| 90 | { |
| 91 | { 2, 3 }, |
| 92 | }, |
| 93 | { |
| 94 | { 4, 5 }, |
| 95 | { 6 }, |
| 96 | }, |
| 97 | }; |
| 98 | } |
| 99 | |
| 100 | void legal() { |
| 101 | short q[][3][2] = { |
| 102 | { 1 }, |
| 103 | { 2, 3 }, |
| 104 | { 4, 5, 6 } |
| 105 | }; |
Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 106 | int q_sizecheck[(sizeof(q) / sizeof(short [3][2])) == 3? 1 : -1]; |
Steve Naroff | 371227d | 2007-09-04 02:20:04 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Steve Naroff | fd8b4a4 | 2007-10-18 03:27:23 +0000 | [diff] [blame] | 109 | unsigned char asso_values[] = { 34 }; |
| 110 | int legal2() { |
| 111 | return asso_values[0]; |
| 112 | } |
| 113 | |
Steve Naroff | 371227d | 2007-09-04 02:20:04 +0000 | [diff] [blame] | 114 | void illegal() { |
| 115 | short q2[4][][2] = { // expected-error{{array has incomplete element type 'short [][2]'}} |
| 116 | { 1, 0, 0, 0, 0, 0 }, |
| 117 | { 2, 3, 0, 0, 0, 0 }, |
| 118 | { 4, 5, 6 } |
| 119 | }; |
| 120 | short q3[4][3][] = { // expected-error{{array has incomplete element type 'short []'}} |
| 121 | { |
| 122 | { 1 }, |
| 123 | }, |
| 124 | { |
| 125 | { 2, 3 }, |
| 126 | }, |
| 127 | { |
| 128 | { 4, 5 }, |
| 129 | { 6 }, |
| 130 | }, |
| 131 | }; |
Chris Lattner | fd89bc8 | 2008-04-02 01:05:10 +0000 | [diff] [blame] | 132 | int a[][] = { 1, 2 }; // expected-error{{array has incomplete element type 'int []'}} |
Steve Naroff | 371227d | 2007-09-04 02:20:04 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | typedef int AryT[]; |
| 136 | |
| 137 | void testTypedef() |
| 138 | { |
| 139 | AryT a = { 1, 2 }, b = { 3, 4, 5 }; |
Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 140 | int a_sizecheck[(sizeof(a) / sizeof(int)) == 2? 1 : -1]; |
| 141 | int b_sizecheck[(sizeof(b) / sizeof(int)) == 3? 1 : -1]; |
Steve Naroff | 371227d | 2007-09-04 02:20:04 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Steve Naroff | 2fdc374 | 2007-12-10 22:44:33 +0000 | [diff] [blame] | 144 | static char const xx[] = "test"; |
Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 145 | int xx_sizecheck[(sizeof(xx) / sizeof(char)) == 5? 1 : -1]; |
Steve Naroff | 2fdc374 | 2007-12-10 22:44:33 +0000 | [diff] [blame] | 146 | static char const yy[5] = "test"; |
| 147 | static char const zz[3] = "test"; // expected-warning{{initializer-string for char array is too long}} |
| 148 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 149 | void charArrays() { |
| 150 | static char const test[] = "test"; |
| 151 | int test_sizecheck[(sizeof(test) / sizeof(char)) == 5? 1 : -1]; |
| 152 | static char const test2[] = { "weird stuff" }; |
| 153 | static char const test3[] = { "test", "excess stuff" }; // expected-warning{{excess elements in char array initializer}} |
Steve Naroff | 2fdc374 | 2007-12-10 22:44:33 +0000 | [diff] [blame] | 154 | |
| 155 | char* cp[] = { "Hello" }; |
| 156 | |
| 157 | char c[] = { "Hello" }; |
| 158 | int l[sizeof(c) == 6 ? 1 : -1]; |
| 159 | |
Douglas Gregor | 08a4190 | 2010-04-09 17:53:29 +0000 | [diff] [blame] | 160 | int i[] = { "Hello "}; // expected-warning{{incompatible pointer to integer conversion initializing 'int' with an expression of type 'char [7]'}} |
Douglas Gregor | 7c53ca6 | 2009-02-18 22:23:55 +0000 | [diff] [blame] | 161 | char c2[] = { "Hello", "Good bye" }; //expected-warning{{excess elements in char array initializer}} |
Steve Naroff | 2fdc374 | 2007-12-10 22:44:33 +0000 | [diff] [blame] | 162 | |
Douglas Gregor | 08a4190 | 2010-04-09 17:53:29 +0000 | [diff] [blame] | 163 | int i2[1] = { "Hello" }; //expected-warning{{incompatible pointer to integer conversion initializing 'int' with an expression of type 'char [6]'}} |
Steve Naroff | 2fdc374 | 2007-12-10 22:44:33 +0000 | [diff] [blame] | 164 | char c3[5] = { "Hello" }; |
| 165 | char c4[4] = { "Hello" }; //expected-warning{{initializer-string for char array is too long}} |
| 166 | |
Daniel Dunbar | 396f0bf | 2008-08-18 20:28:46 +0000 | [diff] [blame] | 167 | int i3[] = {}; //expected-warning{{zero size arrays are an extension}} expected-warning{{use of GNU empty initializer extension}} |
Steve Naroff | 2fdc374 | 2007-12-10 22:44:33 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Steve Naroff | ca10730 | 2008-01-21 23:53:58 +0000 | [diff] [blame] | 170 | void variableArrayInit() { |
| 171 | int a = 4; |
John McCall | 7307643 | 2012-01-05 00:13:19 +0000 | [diff] [blame] | 172 | char strlit[a] = "foo"; //expected-error{{variable-sized object may not be initialized}} |
Steve Naroff | ca10730 | 2008-01-21 23:53:58 +0000 | [diff] [blame] | 173 | int b[a] = { 1, 2, 4 }; //expected-error{{variable-sized object may not be initialized}} |
| 174 | } |
Steve Naroff | a996033 | 2008-01-25 00:51:06 +0000 | [diff] [blame] | 175 | |
| 176 | // Pure array tests |
| 177 | float r1[10] = {{7}}; //expected-warning{{braces around scalar initializer}} |
| 178 | float r2[] = {{8}}; //expected-warning{{braces around scalar initializer}} |
| 179 | char r3[][5] = {1,2,3,4,5,6}; |
Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 180 | int r3_sizecheck[(sizeof(r3) / sizeof(char[5])) == 2? 1 : -1]; |
Steve Naroff | a996033 | 2008-01-25 00:51:06 +0000 | [diff] [blame] | 181 | char r3_2[sizeof r3 == 10 ? 1 : -1]; |
Douglas Gregor | 7c53ca6 | 2009-02-18 22:23:55 +0000 | [diff] [blame] | 182 | float r4[1][2] = {1,{2},3,4}; //expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in array initializer}} |
Steve Naroff | a996033 | 2008-01-25 00:51:06 +0000 | [diff] [blame] | 183 | char r5[][5] = {"aa", "bbb", "ccccc"}; |
| 184 | char r6[sizeof r5 == 15 ? 1 : -1]; |
| 185 | const char r7[] = "zxcv"; |
| 186 | char r8[5] = "5char"; |
| 187 | char r9[5] = "6chars"; //expected-warning{{initializer-string for char array is too long}} |
| 188 | |
| 189 | int r11[0] = {}; //expected-warning{{zero size arrays are an extension}} expected-warning{{use of GNU empty initializer extension}} |
| 190 | |
| 191 | // Some struct tests |
| 192 | void autoStructTest() { |
| 193 | struct s1 {char a; char b;} t1; |
| 194 | struct s2 {struct s1 c;} t2 = { t1 }; |
| 195 | // The following is a less than great diagnostic (though it's on par with EDG). |
Douglas Gregor | 08a4190 | 2010-04-09 17:53:29 +0000 | [diff] [blame] | 196 | struct s1 t3[] = {t1, t1, "abc", 0}; //expected-warning{{incompatible pointer to integer conversion initializing 'char' with an expression of type 'char [4]'}} |
Steve Naroff | a996033 | 2008-01-25 00:51:06 +0000 | [diff] [blame] | 197 | int t4[sizeof t3 == 6 ? 1 : -1]; |
| 198 | } |
Steve Naroff | 578edc6 | 2008-01-28 02:00:41 +0000 | [diff] [blame] | 199 | struct foo { int z; } w; |
| 200 | int bar (void) { |
Douglas Gregor | 08a4190 | 2010-04-09 17:53:29 +0000 | [diff] [blame] | 201 | struct foo z = { w }; //expected-error{{initializing 'int' with an expression of incompatible type 'struct foo'}} |
Steve Naroff | 578edc6 | 2008-01-28 02:00:41 +0000 | [diff] [blame] | 202 | return z.z; |
| 203 | } |
Steve Naroff | a996033 | 2008-01-25 00:51:06 +0000 | [diff] [blame] | 204 | struct s3 {void (*a)(void);} t5 = {autoStructTest}; |
Douglas Gregor | a645796 | 2009-03-20 00:32:56 +0000 | [diff] [blame] | 205 | struct {int a; int b[];} t6 = {1, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}} \ |
| 206 | // expected-note{{initialized flexible array member 'b' is here}} |
Steve Naroff | a996033 | 2008-01-25 00:51:06 +0000 | [diff] [blame] | 207 | union {char a; int b;} t7[] = {1, 2, 3}; |
| 208 | int t8[sizeof t7 == (3*sizeof(int)) ? 1 : -1]; |
| 209 | |
| 210 | struct bittest{int : 31, a, :21, :12, b;}; |
Douglas Gregor | 7c53ca6 | 2009-02-18 22:23:55 +0000 | [diff] [blame] | 211 | struct bittest bittestvar = {1, 2, 3, 4}; //expected-warning{{excess elements in struct initializer}} |
Steve Naroff | a996033 | 2008-01-25 00:51:06 +0000 | [diff] [blame] | 212 | |
| 213 | // Not completely sure what should happen here... |
Eli Friedman | c56c977 | 2008-05-19 20:29:35 +0000 | [diff] [blame] | 214 | int u1 = {}; //expected-warning{{use of GNU empty initializer extension}} expected-error{{scalar initializer cannot be empty}} |
Eli Friedman | 09865a9 | 2010-08-14 03:14:53 +0000 | [diff] [blame] | 215 | int u2 = {{3}}; //expected-warning{{too many braces around scalar initializer}} |
Steve Naroff | a996033 | 2008-01-25 00:51:06 +0000 | [diff] [blame] | 216 | |
Eli Friedman | 638e144 | 2008-05-25 13:22:35 +0000 | [diff] [blame] | 217 | // PR2362 |
| 218 | void varArray() { |
| 219 | int c[][x] = { 0 }; //expected-error{{variable-sized object may not be initialized}} |
| 220 | } |
Eli Friedman | 402256f | 2008-05-25 13:49:22 +0000 | [diff] [blame] | 221 | |
| 222 | // PR2151 |
Richard Smith | d7c56e1 | 2011-12-29 21:57:33 +0000 | [diff] [blame] | 223 | void emptyInit() {struct {} x[] = {6};} //expected-warning{{empty struct is a GNU extension}} \ |
Douglas Gregor | 0333296 | 2010-07-29 14:29:34 +0000 | [diff] [blame] | 224 | // expected-error{{initializer for aggregate with no elements}} |
Eli Friedman | 402256f | 2008-05-25 13:49:22 +0000 | [diff] [blame] | 225 | |
Mike Stump | d1969d8 | 2009-07-22 00:43:08 +0000 | [diff] [blame] | 226 | void noNamedInit() { |
| 227 | struct {int:5;} x[] = {6}; //expected-error{{initializer for aggregate with no elements}} |
Eli Friedman | f84eda3 | 2008-05-25 14:03:31 +0000 | [diff] [blame] | 228 | } |
| 229 | struct {int a; int:5;} noNamedImplicit[] = {1,2,3}; |
| 230 | int noNamedImplicitCheck[sizeof(noNamedImplicit) == 3 * sizeof(*noNamedImplicit) ? 1 : -1]; |
| 231 | |
Nuno Lopes | 62b6a65 | 2008-09-01 22:28:55 +0000 | [diff] [blame] | 232 | |
| 233 | // ptrs are constant |
| 234 | struct soft_segment_descriptor { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 235 | long ssd_base; |
Nuno Lopes | 62b6a65 | 2008-09-01 22:28:55 +0000 | [diff] [blame] | 236 | }; |
| 237 | static int dblfault_tss; |
| 238 | |
| 239 | union uniao { int ola; } xpto[1]; |
| 240 | |
| 241 | struct soft_segment_descriptor gdt_segs[] = { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 242 | {(long) &dblfault_tss}, |
| 243 | { (long)xpto}, |
Nuno Lopes | 62b6a65 | 2008-09-01 22:28:55 +0000 | [diff] [blame] | 244 | }; |
| 245 | |
Nuno Lopes | 73419bf | 2008-09-01 18:42:41 +0000 | [diff] [blame] | 246 | static void sppp_ipv6cp_up(); |
Richard Smith | d7c56e1 | 2011-12-29 21:57:33 +0000 | [diff] [blame] | 247 | const struct {} ipcp = { sppp_ipv6cp_up }; //expected-warning{{empty struct is a GNU extension}} \ |
Douglas Gregor | 0333296 | 2010-07-29 14:29:34 +0000 | [diff] [blame] | 248 | // expected-warning{{excess elements in struct initializer}} |
Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 249 | |
Hans Wennborg | acbabf1 | 2012-02-03 15:47:04 +0000 | [diff] [blame] | 250 | struct _Matrix { union { float m[4][4]; }; }; //expected-warning{{anonymous unions are a C11 extension}} |
Douglas Gregor | 4c67834 | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 251 | typedef struct _Matrix Matrix; |
| 252 | void test_matrix() { |
| 253 | const Matrix mat1 = { |
| 254 | { { 1.0f, 2.0f, 3.0f, 4.0f, |
| 255 | 5.0f, 6.0f, 7.0f, 8.0f, |
| 256 | 9.0f, 10.0f, 11.0f, 12.0f, |
| 257 | 13.0f, 14.0f, 15.0f, 16.0f } } |
| 258 | }; |
| 259 | |
| 260 | const Matrix mat2 = { |
| 261 | 1.0f, 2.0f, 3.0f, 4.0f, |
| 262 | 5.0f, 6.0f, 7.0f, 8.0f, |
| 263 | 9.0f, 10.0f, 11.0f, 12.0f, |
| 264 | 13.0f, 14.0f, 15.0f, 16.0f |
| 265 | }; |
| 266 | } |
Eli Friedman | e540858 | 2009-05-29 20:20:05 +0000 | [diff] [blame] | 267 | |
| 268 | char badchararray[1] = { badchararray[0], "asdf" }; // expected-warning {{excess elements in array initializer}} expected-error {{initializer element is not a compile-time constant}} |
Douglas Gregor | cd9ec3b | 2011-02-22 18:29:51 +0000 | [diff] [blame] | 269 | |
| 270 | // Test the GNU extension for initializing an array from an array |
| 271 | // compound literal. PR9261. |
| 272 | typedef int int5[5]; |
| 273 | int 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}} |
| 274 | int 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}} |
| 275 | int 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}} |
| 276 | int 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}} |
| 277 | int 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}} |
| 278 | |
| 279 | int a6[5] = (int[]){1, 2, 3}; // expected-error{{cannot initialize array of type 'int [5]' with array of type 'int [3]'}} |
| 280 | |
| 281 | int nonconst_value(); |
| 282 | int a7[5] = (int[5]){ 1, 2, 3, 4, nonconst_value() }; // expected-error{{initializer element is not a compile-time constant}} |
John McCall | 7307643 | 2012-01-05 00:13:19 +0000 | [diff] [blame] | 283 | |
| 284 | // <rdar://problem/10636946> |
| 285 | __attribute__((weak)) const unsigned int test10_bound = 10; |
| 286 | char test10_global[test10_bound]; // expected-error {{variable length array declaration not allowed at file scope}} |
| 287 | void test10() { |
| 288 | char test10_local[test10_bound] = "help"; // expected-error {{variable-sized object may not be initialized}} |
| 289 | } |