array-init.c revision 38374b05791ee93300b9fbe8ceb3957f54184b37
1// RUN: clang -parse-ast-check -pedantic %s
2
3static 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
10static int ary3[] = { 1, "abc", 3 }; // expected-warning{{incompatible types assigning 'char *' to 'int'}}
11
12void func() {
13  int x = 1;
14
15  //int x2[] = { 1, 3, 5 };
16
17  int x3[x] = { 1, 2 }; // expected-error{{variable-sized object may not be initialized}}
18
19  int x4 = { 1, 2 }; // gcc-warning {{excess elements in array initializer}}
20
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
31  struct threeElements {
32    int a,b,c;
33  } z = { 1 };
34
35  struct threeElements *p = 7; // expected-warning{{incompatible types assigning 'int' to 'struct threeElements *'}}
36
37  extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}}
38
39  static int x2[3] = { 1.0, "abc" , 5.8 }; // expected-warning{{incompatible types assigning 'char *' to 'int'}}
40}
41