2 // { dg-additional-options "-Wpedantic -Wno-error=pedantic" }
4 // Verify that flexible array members are recognized as either valid
5 // or invalid in anonymous structs (a G++ extension) and C++ anonymous
6 // unions as well as in structs and unions that look anonymous but
12 // The following declares a named data member of an unnamed struct
13 // (i.e., it is not an anonymous struct).
15 int a[]; // { dg-error "in an otherwise empty" }
24 int a[]; // { dg-error "in an otherwise empty" }
33 int a[]; // { dg-error "in an otherwise empty" }
42 int a[]; // { dg-error "in an otherwise empty" }
51 int a[]; // { dg-error "in an otherwise empty" }
60 int a[]; // { dg-error "in an otherwise empty" }
69 int a[]; // { dg-error "in an otherwise empty" }
78 int a[]; // { dg-error "in an otherwise empty" }
87 int a[]; // { dg-error "in an otherwise empty" }
96 int a[]; // { dg-error "in an otherwise empty" }
105 int a[]; // { dg-error "in an otherwise empty" }
114 int a[]; // { dg-error "in an otherwise empty" }
123 int a[]; // { dg-error "in an otherwise empty" }
132 int a[]; // { dg-error "in an otherwise empty" }
141 int a[]; // { dg-error "in an otherwise empty" }
149 struct { // { dg-warning "invalid use" }
150 // A flexible array as a sole member of an anonymous struct is
151 // rejected with an error in C mode but emits just a pedantic
152 // warning in C++. Other than excessive pedantry there is no
153 // reason to reject it.
155 }; // { dg-warning "anonymous struct" }
162 union { // anonymous union
163 int a[]; // { dg-error "flexible array member in union" }
172 int j, a[]; // { dg-message "declared here" }
173 } s; // { dg-warning "invalid use" }
180 struct { // { dg-warning "invalid use" }
181 int j, a[]; // { dg-message "declared here" }
182 }; // { dg-warning "anonymous struct" }
192 A a; // { dg-message "declared here" }
193 } s; // { dg-warning "invalid use" }
201 struct { // { dg-warning "invalid use" }
203 A a; // { dg-message "declared here" }
204 }; // { dg-warning "anonymous struct" }
212 int a[]; // { dg-error "in an otherwise empty" }
219 static int i; // { dg-error "static data member" }
221 int a[]; // { dg-error "in an otherwise empty" }
222 }; // { dg-warning "anonymous struct" }
230 int a[]; // { dg-error "in an otherwise empty" }
239 int j, a[]; // { dg-message "declared here" }
240 } s; // { dg-warning "invalid use" }
242 // Verify that a static data member of the enclosing class doesn't
243 // cause infinite recursion or some such badness.
255 int a[]; // { dg-error "in an otherwise empty" }
282 // Verify that the notes printed along with the warnings point to the types
283 // or members they should point to and mention the correct relationships
284 // with the flexible array members.
291 int i, a[]; // { dg-message "declared here" }
292 } c; // { dg-warning "invalid use" }
300 struct { // { dg-warning "invalid use" }
301 int i, a[]; // { dg-message "declared here" }
302 }; // { dg-warning "anonymous struct" }
303 }; // { dg-warning "anonymous struct" }
309 typedef struct Opaque* P29;
310 struct S30 { P29 p; };
311 struct S31 { S30 s; };
313 typedef struct { } S32;
314 typedef struct { S32 *ps32; } S33;
344 // { dg-prune-output "forbids flexible array member" }