2007-09-27 04:14:22 +08:00
|
|
|
// RUN: clang -parse-ast -verify -pedantic %s
|
2007-09-02 10:04:30 +08:00
|
|
|
|
2007-09-13 04:13:48 +08:00
|
|
|
extern int foof() = 1; // expected-error{{illegal initializer (only variables can be initialized)}}
|
|
|
|
|
2007-09-02 23:34:30 +08:00
|
|
|
static int x, y, z;
|
|
|
|
|
|
|
|
static int ary[] = { x, y, z }; // expected-error{{initializer element is not constant}}
|
|
|
|
int ary2[] = { x, y, z }; // expected-error{{initializer element is not constant}}
|
|
|
|
|
|
|
|
extern int fileScopeExtern[3] = { 1, 3, 5 }; // expected-warning{{'extern' variable has an initializer}}
|
|
|
|
|
2007-09-03 09:24:23 +08:00
|
|
|
static int ary3[] = { 1, "abc", 3, 4 }; // expected-warning{{incompatible types assigning 'char *' to 'int'}}
|
2007-09-03 04:30:18 +08:00
|
|
|
|
2007-09-02 10:04:30 +08:00
|
|
|
void func() {
|
|
|
|
int x = 1;
|
|
|
|
|
2007-09-13 04:13:48 +08:00
|
|
|
typedef int TInt = 1; // expected-error{{illegal initializer (only variables can be initialized)}}
|
|
|
|
|
2007-09-03 09:24:23 +08:00
|
|
|
int xComputeSize[] = { 1, 3, 5 };
|
2007-09-02 10:04:30 +08:00
|
|
|
|
2007-09-03 04:30:18 +08:00
|
|
|
int x3[x] = { 1, 2 }; // expected-error{{variable-sized object may not be initialized}}
|
2007-09-02 10:04:30 +08:00
|
|
|
|
2007-09-04 10:20:04 +08:00
|
|
|
int x4 = { 1, 2 }; // expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in array initializer}}
|
2007-09-02 10:04:30 +08:00
|
|
|
|
|
|
|
int y[4][3] = {
|
|
|
|
{ 1, 3, 5 },
|
|
|
|
{ 2, 4, 6 },
|
|
|
|
{ 3, 5, 7 },
|
|
|
|
};
|
|
|
|
|
|
|
|
int y2[4][3] = {
|
|
|
|
1, 3, 5, 2, 4, 6, 3, 5, 7
|
|
|
|
};
|
|
|
|
|
2007-09-03 09:24:23 +08:00
|
|
|
int y3[4][3] = {
|
|
|
|
{ 1, 3, 5 },
|
|
|
|
{ 2, 4, 6 },
|
|
|
|
{ 3, 5, 7 },
|
|
|
|
{ 4, 6, 8 },
|
|
|
|
{ 5 }, // expected-warning{{excess elements in array initializer}}
|
|
|
|
};
|
|
|
|
|
2007-09-02 10:04:30 +08:00
|
|
|
struct threeElements {
|
|
|
|
int a,b,c;
|
|
|
|
} z = { 1 };
|
|
|
|
|
|
|
|
struct threeElements *p = 7; // expected-warning{{incompatible types assigning 'int' to 'struct threeElements *'}}
|
2007-09-02 23:34:30 +08:00
|
|
|
|
|
|
|
extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}}
|
2007-09-03 04:30:18 +08:00
|
|
|
|
|
|
|
static int x2[3] = { 1.0, "abc" , 5.8 }; // expected-warning{{incompatible types assigning 'char *' to 'int'}}
|
2007-09-02 10:04:30 +08:00
|
|
|
}
|
2007-09-04 10:20:04 +08:00
|
|
|
|
|
|
|
void test() {
|
|
|
|
int y1[3] = {
|
|
|
|
{ 1, 2, 3 } // expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in array initializer}}
|
|
|
|
};
|
|
|
|
int y3[4][3] = {
|
|
|
|
{ 1, 3, 5 },
|
|
|
|
{ 2, 4, 6 },
|
|
|
|
{ 3, 5, 7 },
|
|
|
|
{ 4, 6, 8 },
|
|
|
|
{ }, // expected-warning{{use of GNU empty initializer extension}} expected-warning{{excess elements in array initializer}}
|
|
|
|
};
|
|
|
|
int y4[4][3] = {
|
|
|
|
{ 1, 3, 5, 2 }, // expected-warning{{excess elements in array initializer}}
|
|
|
|
{ 4, 6 },
|
|
|
|
{ 3, 5, 7 },
|
|
|
|
{ 4, 6, 8 }, // expected-warning{{excess elements in array initializer}}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void allLegalAndSynonymous() {
|
|
|
|
short q[4][3][2] = {
|
|
|
|
{ 1 },
|
|
|
|
{ 2, 3 },
|
|
|
|
{ 4, 5, 6 }
|
|
|
|
};
|
|
|
|
short q2[4][3][2] = {
|
|
|
|
{ 1, 0, 0, 0, 0, 0 },
|
|
|
|
{ 2, 3, 0, 0, 0, 0 },
|
|
|
|
{ 4, 5, 6 }
|
|
|
|
};
|
|
|
|
short q3[4][3][2] = {
|
|
|
|
{
|
|
|
|
{ 1 },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{ 2, 3 },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{ 4, 5 },
|
|
|
|
{ 6 },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void legal() {
|
|
|
|
short q[][3][2] = {
|
|
|
|
{ 1 },
|
|
|
|
{ 2, 3 },
|
|
|
|
{ 4, 5, 6 }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void illegal() {
|
|
|
|
short q2[4][][2] = { // expected-error{{array has incomplete element type 'short [][2]'}}
|
|
|
|
{ 1, 0, 0, 0, 0, 0 },
|
|
|
|
{ 2, 3, 0, 0, 0, 0 },
|
|
|
|
{ 4, 5, 6 }
|
|
|
|
};
|
|
|
|
short q3[4][3][] = { // expected-error{{array has incomplete element type 'short []'}}
|
|
|
|
{
|
|
|
|
{ 1 },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{ 2, 3 },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{ 4, 5 },
|
|
|
|
{ 6 },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
// FIXME: the following two errors are redundant
|
|
|
|
int a[][] = { 1, 2 }; // expected-error{{array has incomplete element type 'int []'}} expected-error{{variable has incomplete type 'int []'}}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef int AryT[];
|
|
|
|
|
|
|
|
void testTypedef()
|
|
|
|
{
|
|
|
|
AryT a = { 1, 2 }, b = { 3, 4, 5 };
|
|
|
|
}
|
|
|
|
|