1 /* Test diagnostics for various bad initializers. */
2 /* Origin: Joseph Myers <joseph@codesourcery.com> */
3 /* { dg-do compile } */
4 /* { dg-options "-std=gnu99" } */
7 void g(void) = f
; /* { dg-error "function 'g' is initialized like a variable" } */
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 } */
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 } */
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 } */