annotate gcc/testsuite/g++.dg/ext/flexary5.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // { dg-do compile }
kono
parents:
diff changeset
2 // { dg-options "-Wno-error=pedantic" }
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 // Test to verify flexible array members handling in base and derived
kono
parents:
diff changeset
5 // classes.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 #include "flexary.h"
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 template <class T>
kono
parents:
diff changeset
10 struct S_no_diag: T {
kono
parents:
diff changeset
11 char a[]; // cannot be diagnosed unless/until T is known
kono
parents:
diff changeset
12 };
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 template <class T>
kono
parents:
diff changeset
15 struct STx_1: T {
kono
parents:
diff changeset
16 char a[]; // { dg-error "flexible array member" }
kono
parents:
diff changeset
17 };
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 template <class T, int I>
kono
parents:
diff changeset
20 struct STI: T {
kono
parents:
diff changeset
21 char a[I]; // cannot be diagnosed unless/until T and I are known
kono
parents:
diff changeset
22 };
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 template <class T, int I>
kono
parents:
diff changeset
25 struct STIx: T {
kono
parents:
diff changeset
26 char a[I];
kono
parents:
diff changeset
27 };
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 template <int> struct E { };
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 STx_1<E<0> > stx_empty_1;
kono
parents:
diff changeset
32 STIx<E<0>, 0> stix_empty_1;
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 // Verify that a sole flexible array member in a class with all empty
kono
parents:
diff changeset
35 // base classes is diagnosed.
kono
parents:
diff changeset
36 struct E1: E<0>, E<1> { };
kono
parents:
diff changeset
37 struct E2: E<2>, E<3> { };
kono
parents:
diff changeset
38 struct D1: E1, E2
kono
parents:
diff changeset
39 {
kono
parents:
diff changeset
40 char a[]; // { dg-error "flexible array member" }
kono
parents:
diff changeset
41 };
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 struct NE { size_t i; };
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 struct A1x { int n, a[]; };
kono
parents:
diff changeset
46 struct D2: A1x, E1, E2 { };
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 // Verify that the offset of the flexible array member is equal
kono
parents:
diff changeset
49 // to the size of each of the valid structs.
kono
parents:
diff changeset
50 ASSERT_AT_END (D2, a);
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 struct D3: E1, A1x, E2 { };
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 ASSERT_AT_END (D3, a);
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 struct D4: E1, E2, A1x { };
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 ASSERT_AT_END (D4, a);
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 // Class with non-static data members and at least one base class
kono
parents:
diff changeset
61 // with such a member is not a standard layout class. The warning
kono
parents:
diff changeset
62 // below is benign since GCC computes the expected value.
kono
parents:
diff changeset
63 struct D5: E1, E2, NE { char a[]; };
kono
parents:
diff changeset
64
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
65 ASSERT_AT_END (D5, a); // { dg-warning "'offsetof' within non-standard-layout" }
111
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 struct A2x_1 {
kono
parents:
diff changeset
68 size_t n;
kono
parents:
diff changeset
69 size_t a[]; // { dg-error "not at end of .struct D6." }
kono
parents:
diff changeset
70 };
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 struct A2x_2 {
kono
parents:
diff changeset
73 size_t n;
kono
parents:
diff changeset
74 size_t a[]; // { dg-error "not at end of .struct D7." }
kono
parents:
diff changeset
75 };
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 struct A2x_3 {
kono
parents:
diff changeset
78 size_t n;
kono
parents:
diff changeset
79 size_t a[]; // { dg-error "not at end of .struct D8." }
kono
parents:
diff changeset
80 };
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 // Verify that the flexible array member in A2x above is diagnosed
kono
parents:
diff changeset
83 // for each of the three struct defintions below which also derive
kono
parents:
diff changeset
84 // from another struct with a flexible array member.
kono
parents:
diff changeset
85 struct D6: A2x_1, E1, A1x { };
kono
parents:
diff changeset
86 struct D7: E1, A2x_2, E2, A1x { };
kono
parents:
diff changeset
87 struct D8: E1, E2, A2x_3, A1x { };
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 struct DA2x: A2x_1 { };
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 struct D9: DA2x, E1, E2 { };
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 ASSERT_AT_END (D9, a);
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 struct D10: E1, DA2x, E2 { };
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 ASSERT_AT_END (D10, a);
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 struct D11: E1, E2, DA2x { };
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 ASSERT_AT_END (D11, a);
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 struct A3x {
kono
parents:
diff changeset
104 size_t n;
kono
parents:
diff changeset
105 size_t a[]; // { dg-error "not at end of .struct D12.| D13.| D14.| D15." }
kono
parents:
diff changeset
106 };
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 // Verify that the flexible array member in A3x above is diagnosed
kono
parents:
diff changeset
109 // for each of the three struct defintions below which also derive
kono
parents:
diff changeset
110 // from another struct with a non-static member.
kono
parents:
diff changeset
111 struct D12: A3x, E1, NE { };
kono
parents:
diff changeset
112 struct D13: E1, A3x, NE { };
kono
parents:
diff changeset
113 struct D14: E1, E2, A3x, NE { };
kono
parents:
diff changeset
114 struct D15: E1, E2, NE, A3x { };
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 struct A4x {
kono
parents:
diff changeset
117 A4x ();
kono
parents:
diff changeset
118 ~A4x ();
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 size_t n;
kono
parents:
diff changeset
121 struct AS {
kono
parents:
diff changeset
122 AS (int);
kono
parents:
diff changeset
123 ~AS ();
kono
parents:
diff changeset
124 size_t i;
kono
parents:
diff changeset
125 } a[];
kono
parents:
diff changeset
126 };
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 struct D16: A4x, E1, E2 { };
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 ASSERT_AT_END (D16, a);
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 struct D17: E1, A4x, E2 { };
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 ASSERT_AT_END (D17, a);
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 struct D18: E1, E2, A4x { };
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 ASSERT_AT_END (D18, a);
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 struct DA4x: A4x { };
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 struct D19: DA4x, E1, E2 { };
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 ASSERT_AT_END (D19, a);
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 struct D20: E1, DA4x, E2 { };
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 ASSERT_AT_END (D20, a);
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 struct D21: E1, E2, DA4x { };
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 ASSERT_AT_END (D21, a);
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 struct A5x {
kono
parents:
diff changeset
156 A5x (int);
kono
parents:
diff changeset
157 virtual ~A5x ();
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 size_t n;
kono
parents:
diff changeset
160 struct AS {
kono
parents:
diff changeset
161 AS (int);
kono
parents:
diff changeset
162 ~AS ();
kono
parents:
diff changeset
163 size_t i;
kono
parents:
diff changeset
164 } a[];
kono
parents:
diff changeset
165 };
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 struct D22: A5x, E1, E2 { };
kono
parents:
diff changeset
168
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
169 ASSERT_AT_END (D22, a); // { dg-warning "'offsetof' within non-standard-layout" }
111
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 struct D23: E1, A5x, E2 { };
kono
parents:
diff changeset
172
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
173 ASSERT_AT_END (D23, a); // { dg-warning "'offsetof' within non-standard-layout" }
111
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 struct D24: E1, E2, A5x { };
kono
parents:
diff changeset
176
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
177 ASSERT_AT_END (D24, a); // { dg-warning "'offsetof' within non-standard-layout" }
111
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 struct DA5x: A5x { };
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 struct D25: DA5x, E1, E2 { };
kono
parents:
diff changeset
182
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
183 ASSERT_AT_END (D25, a); // { dg-warning "'offsetof' within non-standard-layout" }
111
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 struct D26: E1, DA5x, E2 { };
kono
parents:
diff changeset
186
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
187 ASSERT_AT_END (D26, a); // { dg-warning "'offsetof' within non-standard-layout" }
111
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 struct D27: E1, E2, DA5x { };
kono
parents:
diff changeset
190
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
191 ASSERT_AT_END (D27, a); // { dg-warning "'offsetof' within non-standard-layout" }
111
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 // Verfify that a flexible array member is diagnosed even when deep
kono
parents:
diff changeset
194 // in the base class hierarchy.
kono
parents:
diff changeset
195 struct A6x {
kono
parents:
diff changeset
196 size_t n;
kono
parents:
diff changeset
197 size_t a[]; // { dg-error "not at end of .struct D28.| D29." }
kono
parents:
diff changeset
198 };
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 struct AA6x: A6x { };
kono
parents:
diff changeset
201 struct NE1: NE { };
kono
parents:
diff changeset
202 struct NE2: NE { };
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 struct D28: NE1, AA6x { };
kono
parents:
diff changeset
205 struct D29: AA6x, NE1 { };
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 struct A7x {
kono
parents:
diff changeset
208 size_t n;
kono
parents:
diff changeset
209 size_t a[]; // { dg-error "flexible array member .A7x::a. not at end of .struct D33." }
kono
parents:
diff changeset
210 };
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 // Verify that a flexible array member in a virtual base class is not
kono
parents:
diff changeset
213 // diagnosed.
kono
parents:
diff changeset
214 struct DA7xV1: virtual A7x { };
kono
parents:
diff changeset
215 struct DA7xV2: virtual A7x { };
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 struct D30: DA7xV1, DA7xV2 { };
kono
parents:
diff changeset
218 struct D31: DA7xV1, DA7xV2 { };
kono
parents:
diff changeset
219 struct D32: D30, D31 { };
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 // Verify the diagnostic when the flexible array is in an anonymous struct.
kono
parents:
diff changeset
222 struct A8x {
kono
parents:
diff changeset
223 struct { // { dg-message "next member .A8x::<unnamed struct> A8x::<anonymous>. declared here" }
kono
parents:
diff changeset
224 size_t n;
kono
parents:
diff changeset
225 size_t a[];
kono
parents:
diff changeset
226 };
kono
parents:
diff changeset
227 };
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 struct D33: // { dg-message "in the definition of .struct D33." }
kono
parents:
diff changeset
230 A7x, A8x { };