Debian Codegraph @

gcc/testsuite/g++.dg/warn/Warray-bounds-9.C

raw
1 /* PR c++/88565 - enhance -Warray-bounds for C++ trailing class member arrays
2 { dg-do compile }
3 { dg-options "-O2 -Wall" } */
4
5 struct S0
6 {
7 S0 ();
8
9 int f ();
10
11 int a[0];
12 };
13
14 int S0::f ()
15 {
16 // The following is not diagnosed but should be in a class with a ctor.
17 return a[0]; // { dg-warning "\\\[-Warray-bounds" "pr88565" { xfail *-*-* } }
18 }
19
20
21 struct S1
22 {
23 S1 ();
24
25 int f ();
26
27 int a[1];
28 };
29
30 int S1::f ()
31 {
32 // The following is only diagnosed with -Warray-bounds=2 but should
33 // be even at level 1 in a call with a ctor.
34 return a[1]; // { dg-warning "\\\[-Warray-bounds" "pr88565" { xfail *-*-* } }
35 }
36
37
38 struct S2
39 {
40 S2 ();
41
42 int f ();
43
44 int a[2];
45 };
46
47 int S2::f ()
48 {
49 return a[2]; // { dg-warning "\\\[-Warray-bounds" }
50 }
51
52
53 struct S3
54 {
55 S3 ();
56
57 int f ();
58
59 int a[3];
60 };
61
62 int S3::f ()
63 {
64 return a[3]; // { dg-warning "\\\[-Warray-bounds" }
65 }
66
67
68 struct Sx
69 {
70 Sx ();
71
72 int f ();
73
74 int n, a[];
75 };
76
77 int Sx::f ()
78 {
79 // The following is not diagnosed but should be in a class with a ctor.
80 return a[0]; // { dg-warning "\\\[-Warray-bounds" "pr88565" { xfail *-*-* } }
81 }