| 1 |
/* PR c/61077 */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-options "-std=gnu99 -fshort-enums -fshort-wchar -Wpedantic" } */ |
| 4 |
/* { dg-prune-output ".*near initialization for.*" } */ |
| 5 |
|
| 6 |
typedef enum { A } schar; |
| 7 |
extern int e; |
| 8 |
struct S |
| 9 |
{ |
| 10 |
int a[3]; |
| 11 |
}; |
| 12 |
struct f |
| 13 |
{ |
| 14 |
int w; |
| 15 |
int x[]; |
| 16 |
}; |
| 17 |
struct g |
| 18 |
{ |
| 19 |
struct f f; /* { dg-warning "invalid use of structure with flexible array member" } */ |
| 20 |
}; |
| 21 |
|
| 22 |
char w1[] = L"foo"; /* { dg-error "13:array of .char. from a string literal with type array of" } */ |
| 23 |
__WCHAR_TYPE__ w2[] = "foo"; /* { dg-error "23:from a string literal with type array of .char." } */ |
| 24 |
__WCHAR_TYPE__ w3[] = U"foo"; /* { dg-error "23:from a string literal with type array of" } */ |
| 25 |
schar a1[] = "foo"; /* { dg-error "14:array of inappropriate type initialized from string constant" } */ |
| 26 |
int a2[] = (int[]) { 1 }; /* { dg-warning "12:initializer element is not constant" } */ |
| 27 |
|
| 28 |
int a3 = e; /* { dg-error "10:initializer element is not constant" } */ |
| 29 |
int a4 = (e, 1); /* { dg-error "10:initializer element is not constant" } */ |
| 30 |
int a5 = a1[0]; /* { dg-error "10:initializer element is not constant" } */ |
| 31 |
int a6 = &a3 - &a4; /* { dg-error "10:initializer element is not" } */ |
| 32 |
int a7[] = a7; /* { dg-error "12:invalid initializer" } */ |
| 33 |
|
| 34 |
struct S s = { { 1 }, { 3 } }; /* { dg-error "23:extra brace group at end of initializer" } */ |
| 35 |
/* { dg-warning "23:excess elements in struct initializer" "" { target *-*-* } .-1 } */ |
| 36 |
struct g g1 = { {0, { 1 } } }; /* { dg-error "21:initialization of flexible array member in a nested context" } */ |
| 37 |
struct g g2 = { .f[0] = 1 }; /* { dg-error "20:array index in non-array initializer" } */ |
| 38 |
|
| 39 |
__extension__ int a8 = { }; |
| 40 |
int a9[10] = {[1.2] = 2 }; /* { dg-error "16:array index in initializer not of integer type" } */ |
| 41 |
int a10[10] = {[e] = 2 }; /* { dg-error "17:nonconstant array index in initializer" } */ |
| 42 |
__extension__ int a11[10] = {[1 ... e] = 1 }; /* { dg-error "31:nonconstant array index in initializer" } */ |
| 43 |
int a12 = {[1] = 2 }; /* { dg-error "13:array index in non-array initializer" } */ |
| 44 |
int a13[2] = {[-1] = 4 }; /* { dg-error "16:array index in initializer exceeds array bounds" } */ |
| 45 |
int a14[2] = {[64] = 4 }; /* { dg-error "16:array index in initializer exceeds array bounds" } */ |
| 46 |
__extension__ int a15[10] = {[2 ... 1] = 4 }; /* { dg-error "31:empty index range in initializer" } */ |
| 47 |
__extension__ int a16[10] = {[2 ... 100] = 4 }; /* { dg-error "31:array index range in initializer exceeds array bounds" } */ |
| 48 |
int a17[] = { .B = 1 }; /* { dg-error "15:field name not in record or union initializer" } */ |
| 49 |
int a18[] = { e }; /* { dg-error "15:initializer element is not constant" } */ |
| 50 |
char a19[1] = { "x", "x" }; /* { dg-error "22:excess elements in 'char.1.' initializer" } */ |
| 51 |
|
| 52 |
void |
| 53 |
bar (void) |
| 54 |
{ |
| 55 |
struct f f = { 2, "c" }; /* { dg-error "21:non-static initialization of a flexible array member" } */ |
| 56 |
} |
| 57 |
|
| 58 |
struct |
| 59 |
{ |
| 60 |
char *v; |
| 61 |
} sx[] = { .v = 0 }; /* { dg-error "12:field name not in record or union initializer" } */ |