]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-1.c
Add a new warning option -Wstrict-flex-arrays.
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / Warray-bounds-flex-arrays-1.c
CommitLineData
2a27ae32 1/* Test -fstrict-flex-arrays + -Warray-bounds + -Wstrict-flex-arrays. */
710c9676 2/* { dg-do compile} */
2a27ae32 3/* { dg-options "-O2 -Wstrict-flex-arrays -fstrict-flex-arrays=1 -Warray-bounds" } */
710c9676
QZ
4
5struct trailing_array_1 {
6 int a;
7 int b;
8 int c[4];
9};
10
11struct trailing_array_2 {
12 int a;
13 int b;
14 int c[1];
15};
16
17struct trailing_array_3 {
18 int a;
19 int b;
20 int c[0];
21};
22struct trailing_array_4 {
23 int a;
24 int b;
25 int c[];
26};
27
28void __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 "array subscript 5 is above array bounds of" } */
2a27ae32 35 /*{ dg-warning "should not be used as a flexible array member for level 1 and above" "" { target *-*-* } .-1 } */
710c9676
QZ
36 trailing_1->c[2] = 2; /* { dg-bogus "array subscript " } */
37 trailing_0->c[1] = 1; /* { dg-bogus "array subscript " } */
38 trailing_flex->c[10] = 10; /* { dg-bogus "array subscript " } */
39
40}