1 |
149 |
jeremybenn |
/* Test diagnostics for various bad initializers. */
|
2 |
|
|
/* Origin: Joseph Myers <joseph@codesourcery.com> */
|
3 |
|
|
/* { dg-do compile } */
|
4 |
|
|
/* { dg-options "-std=gnu99" } */
|
5 |
|
|
|
6 |
|
|
void f(void);
|
7 |
|
|
void g(void) = f; /* { dg-error "error: function 'g' is initialized like a variable" } */
|
8 |
|
|
|
9 |
|
|
void h(a)
|
10 |
|
|
int a = 1; /* { dg-error "error: parameter 'a' is initialized" } */
|
11 |
|
|
{
|
12 |
|
|
struct s x = { 0 }; /* { dg-error "error: variable 'x' has initializer but incomplete type" } */
|
13 |
|
|
/* { dg-warning "excess elements|near init" "excess" { target *-*-* } 12 } */
|
14 |
|
|
/* { dg-error "storage size" "size" { target *-*-* } 12 } */
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
char s[1] = "x";
|
18 |
|
|
char s1[1] = { "x" };
|
19 |
|
|
char t[1] = "xy"; /* { dg-warning "warning: initializer-string for array of chars is too long" } */
|
20 |
|
|
char t1[1] = { "xy" }; /* { dg-warning "warning: initializer-string for array of chars is too long" } */
|
21 |
|
|
char u[1] = { "x", "x" }; /* { dg-error "error: excess elements in char array initializer" } */
|
22 |
|
|
/* { dg-error "near init" "near" { target *-*-* } 21 } */
|
23 |
|
|
|
24 |
|
|
int i = { }; /* { dg-error "error: empty scalar initializer" } */
|
25 |
|
|
/* { dg-error "near init" "near" { target *-*-* } 24 } */
|
26 |
|
|
|
27 |
|
|
int j = { 1 };
|
28 |
|
|
|
29 |
|
|
int k = { 1, 2 }; /* { dg-warning "warning: excess elements in scalar initializer" } */
|
30 |
|
|
/* { dg-warning "near init" "near" { target *-*-* } 29 } */
|
31 |
|
|
|
32 |
|
|
int a1[1] = { [1] = 0 }; /* { dg-error "error: array index in initializer exceeds array bounds" } */
|
33 |
|
|
/* { dg-error "near init" "near" { target *-*-* } 32 } */
|
34 |
|
|
int a2[1] = { [-1] = 0 }; /* { dg-error "error: array index in initializer exceeds array bounds" } */
|
35 |
|
|
/* { dg-error "near init" "near" { target *-*-* } 34 } */
|
36 |
|
|
int a3[1] = { [0 ... 1] = 0 }; /* { dg-error "error: array index range in initializer exceeds array bounds" } */
|
37 |
|
|
/* { dg-error "near init" "near" { target *-*-* } 36 } */
|
38 |
|
|
int a4[2] = { [1 ... 0] = 0 }; /* { dg-error "error: empty index range in initializer" } */
|
39 |
|
|
/* { dg-error "near init" "near" { target *-*-* } 38 } */
|
40 |
|
|
int a5[2] = { [0 ... 2] = 0 }; /* { dg-error "error: array index range in initializer exceeds array bounds" } */
|
41 |
|
|
/* { dg-error "near init" "near" { target *-*-* } 40 } */
|
42 |
|
|
int a6[2] = { [-1 ... 1] = 0 }; /* { dg-error "error: array index in initializer exceeds array bounds" } */
|
43 |
|
|
/* { dg-error "near init" "near" { target *-*-* } 42 } */
|
44 |
|
|
int a7[] = { [-1 ... 1] = 0 }; /* { dg-error "error: array index in initializer exceeds array bounds" } */
|
45 |
|
|
/* { dg-error "near init" "near" { target *-*-* } 44 } */
|