Steve Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 1 | // RUN: clang -parse-ast-check -pedantic %s |
| 2 | |
Steve Naroff | 6f9f307 | 2007-09-02 15:34:30 +0000 | [diff] [blame] | 3 | static int x, y, z; |
| 4 | |
| 5 | static int ary[] = { x, y, z }; // expected-error{{initializer element is not constant}} |
| 6 | int ary2[] = { x, y, z }; // expected-error{{initializer element is not constant}} |
| 7 | |
| 8 | extern int fileScopeExtern[3] = { 1, 3, 5 }; // expected-warning{{'extern' variable has an initializer}} |
| 9 | |
Steve Naroff | d35005e | 2007-09-03 01:24:23 +0000 | [diff] [blame] | 10 | static int ary3[] = { 1, "abc", 3, 4 }; // expected-warning{{incompatible types assigning 'char *' to 'int'}} |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 11 | |
Steve Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 12 | void func() { |
| 13 | int x = 1; |
| 14 | |
Steve Naroff | d35005e | 2007-09-03 01:24:23 +0000 | [diff] [blame] | 15 | int xComputeSize[] = { 1, 3, 5 }; |
Steve Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 16 | |
Steve Naroff | 38374b0 | 2007-09-02 20:30:18 +0000 | [diff] [blame] | 17 | 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] | 18 | |
Steve Naroff | 371227d | 2007-09-04 02:20:04 +0000 | [diff] [blame] | 19 | int x4 = { 1, 2 }; // expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in array initializer}} |
Steve Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 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 | |
Steve Naroff | d35005e | 2007-09-03 01:24:23 +0000 | [diff] [blame] | 31 | 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 Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 39 | 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 Naroff | 6f9f307 | 2007-09-02 15:34:30 +0000 | [diff] [blame] | 44 | |
| 45 | 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] | 46 | |
| 47 | static int x2[3] = { 1.0, "abc" , 5.8 }; // expected-warning{{incompatible types assigning 'char *' to 'int'}} |
Steve Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 48 | } |
Steve Naroff | 371227d | 2007-09-04 02:20:04 +0000 | [diff] [blame] | 49 | |
| 50 | void test() { |
| 51 | int y1[3] = { |
| 52 | { 1, 2, 3 } // expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in array initializer}} |
| 53 | }; |
| 54 | int y3[4][3] = { |
| 55 | { 1, 3, 5 }, |
| 56 | { 2, 4, 6 }, |
| 57 | { 3, 5, 7 }, |
| 58 | { 4, 6, 8 }, |
| 59 | { }, // expected-warning{{use of GNU empty initializer extension}} expected-warning{{excess elements in array initializer}} |
| 60 | }; |
| 61 | int y4[4][3] = { |
| 62 | { 1, 3, 5, 2 }, // expected-warning{{excess elements in array initializer}} |
| 63 | { 4, 6 }, |
| 64 | { 3, 5, 7 }, |
| 65 | { 4, 6, 8 }, // expected-warning{{excess elements in array initializer}} |
| 66 | }; |
| 67 | } |
| 68 | |
| 69 | void allLegalAndSynonymous() { |
| 70 | short q[4][3][2] = { |
| 71 | { 1 }, |
| 72 | { 2, 3 }, |
| 73 | { 4, 5, 6 } |
| 74 | }; |
| 75 | short q2[4][3][2] = { |
| 76 | { 1, 0, 0, 0, 0, 0 }, |
| 77 | { 2, 3, 0, 0, 0, 0 }, |
| 78 | { 4, 5, 6 } |
| 79 | }; |
| 80 | short q3[4][3][2] = { |
| 81 | { |
| 82 | { 1 }, |
| 83 | }, |
| 84 | { |
| 85 | { 2, 3 }, |
| 86 | }, |
| 87 | { |
| 88 | { 4, 5 }, |
| 89 | { 6 }, |
| 90 | }, |
| 91 | }; |
| 92 | } |
| 93 | |
| 94 | void legal() { |
| 95 | short q[][3][2] = { |
| 96 | { 1 }, |
| 97 | { 2, 3 }, |
| 98 | { 4, 5, 6 } |
| 99 | }; |
| 100 | } |
| 101 | |
| 102 | void illegal() { |
| 103 | short q2[4][][2] = { // expected-error{{array has incomplete element type 'short [][2]'}} |
| 104 | { 1, 0, 0, 0, 0, 0 }, |
| 105 | { 2, 3, 0, 0, 0, 0 }, |
| 106 | { 4, 5, 6 } |
| 107 | }; |
| 108 | short q3[4][3][] = { // expected-error{{array has incomplete element type 'short []'}} |
| 109 | { |
| 110 | { 1 }, |
| 111 | }, |
| 112 | { |
| 113 | { 2, 3 }, |
| 114 | }, |
| 115 | { |
| 116 | { 4, 5 }, |
| 117 | { 6 }, |
| 118 | }, |
| 119 | }; |
| 120 | // FIXME: the following two errors are redundant |
| 121 | int a[][] = { 1, 2 }; // expected-error{{array has incomplete element type 'int []'}} expected-error{{variable has incomplete type 'int []'}} |
| 122 | } |
| 123 | |
| 124 | typedef int AryT[]; |
| 125 | |
| 126 | void testTypedef() |
| 127 | { |
| 128 | AryT a = { 1, 2 }, b = { 3, 4, 5 }; |
| 129 | } |
| 130 | |