blob: 20daa458384494e81f44669480f3fcbb35bb60ec [file] [log] [blame]
Steve Narofff0090632007-09-02 02:04:30 +00001// RUN: clang -parse-ast-check -pedantic %s
2
Steve Naroff6f9f3072007-09-02 15:34:30 +00003static int x, y, z;
4
5static int ary[] = { x, y, z }; // expected-error{{initializer element is not constant}}
6int ary2[] = { x, y, z }; // expected-error{{initializer element is not constant}}
7
8extern int fileScopeExtern[3] = { 1, 3, 5 }; // expected-warning{{'extern' variable has an initializer}}
9
Steve Naroffd35005e2007-09-03 01:24:23 +000010static int ary3[] = { 1, "abc", 3, 4 }; // expected-warning{{incompatible types assigning 'char *' to 'int'}}
Steve Naroff38374b02007-09-02 20:30:18 +000011
Steve Narofff0090632007-09-02 02:04:30 +000012void func() {
13 int x = 1;
14
Steve Naroffd35005e2007-09-03 01:24:23 +000015 int xComputeSize[] = { 1, 3, 5 };
Steve Narofff0090632007-09-02 02:04:30 +000016
Steve Naroff38374b02007-09-02 20:30:18 +000017 int x3[x] = { 1, 2 }; // expected-error{{variable-sized object may not be initialized}}
Steve Narofff0090632007-09-02 02:04:30 +000018
Steve Naroffd35005e2007-09-03 01:24:23 +000019 int x4 = { 1, 2 }; // // expected-warning{{excess elements in array initializer}}
Steve Narofff0090632007-09-02 02:04:30 +000020
21 int y[4][3] = {
22 { 1, 3, 5 },
23 { 2, 4, 6 },
24 { 3, 5, 7 },
25 };
26
27 int y2[4][3] = {
28 1, 3, 5, 2, 4, 6, 3, 5, 7
29 };
30
Steve Naroffd35005e2007-09-03 01:24:23 +000031 int y3[4][3] = {
32 { 1, 3, 5 },
33 { 2, 4, 6 },
34 { 3, 5, 7 },
35 { 4, 6, 8 },
36 { 5 }, // expected-warning{{excess elements in array initializer}}
37 };
38
Steve Narofff0090632007-09-02 02:04:30 +000039 struct threeElements {
40 int a,b,c;
41 } z = { 1 };
42
43 struct threeElements *p = 7; // expected-warning{{incompatible types assigning 'int' to 'struct threeElements *'}}
Steve Naroff6f9f3072007-09-02 15:34:30 +000044
45 extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}}
Steve Naroff38374b02007-09-02 20:30:18 +000046
47 static int x2[3] = { 1.0, "abc" , 5.8 }; // expected-warning{{incompatible types assigning 'char *' to 'int'}}
Steve Narofff0090632007-09-02 02:04:30 +000048}