1 /* Test -Wstrict-flex-arrays. */
2 /* { dg-do compile } */
3 /* { dg-options "-O2 -Wstrict-flex-arrays -fstrict-flex-arrays=2" } */
4
5 struct trailing_array_1 {
6 int a;
7 int b;
8 int c[4];
9 };
10
11 struct trailing_array_2 {
12 int a;
13 int b;
14 int c[1];
15 };
16
17 struct trailing_array_3 {
18 int a;
19 int b;
20 int c[0];
21 };
22 struct trailing_array_4 {
23 int a;
24 int b;
25 int c[];
26 };
27
28 void __attribute__((__noinline__)) stuff(
29 struct trailing_array_1 *normal,
30 struct trailing_array_2 *trailing_1,
31 struct trailing_array_3 *trailing_0,
32 struct trailing_array_4 *trailing_flex)
33 {
34 normal->c[5] = 5; /*{ dg-warning "should not be used as a flexible array member" } */
35 trailing_1->c[2] = 2; /* { dg-warning "should not be used as a flexible array member" } */
36 trailing_0->c[1] = 1; /* { dg-bogus "should not be used as a flexible array member" } */
37 trailing_flex->c[10] = 10; /* { dg-bogus "should not be used as a flexible array member" } */
38
39 }