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