1 // PR c++/71912 - [6/7 regression] flexible array in struct in union rejected
3 // { dg-additional-options "-Wpedantic -Wno-error=pedantic" }
13 char s[]; // { dg-message "array member .char pr71912::foo::s \\\[\\\]. declared here" }
26 // The definition of struct foo is fine but the use of struct foo
27 // in the definition of u below is what's invalid and must be clearly
29 u; // { dg-warning "invalid use of .struct pr71912::foo. with a flexible array member in .struct pr71912::baz." }
36 char s[]; // { dg-message "declared here" }
42 } u; // { dg-warning "invalid use" }
54 // The following definitions aren't strictly valid but, like those above,
55 // are accepted for compatibility with GCC (in C mode). They are benign
56 // in that the flexible array member is at the highest offset within
57 // the outermost type and doesn't overlap with other members except for
58 // those of the union.
60 struct { int n1, a[]; } s;
65 struct { int n1, a1[]; } s1;
66 struct { int n2, a2[]; } s2;
71 struct { int n1, a1[]; } s1;
72 struct { double n2, a2[]; } s2;
77 struct { int n1, a1[]; } s1;
78 struct { struct { int n2, a2[]; } s2; } s3;
83 struct { struct { int n1, a1[]; } s1; } s2; // { dg-warning "invalid use" }
84 struct { double n2, a2[]; } s3;
89 struct { struct { int n1, a1[]; } s1; } s2; // { dg-warning "invalid use" }
90 struct { struct { int n2, a2[]; } s3; } s4;
95 struct { int n1, a1[]; } s1;
96 struct { double n2, a2[]; } s2;
97 struct { struct { int n3, a3[]; } s3; } s4;
101 struct { int n1, a1[]; } s1;
102 struct { struct { int n2, a2[]; } s2; } s3;
103 struct { struct { int n3, a3[]; } s4; } s5;
107 struct { struct { int n1, a1[]; } s1; } s2; // { dg-warning "invalid use" }
108 struct { struct { int n2, a2[]; } s3; } s4;
109 struct { struct { int n3, a3[]; } s5; } s6;
112 struct StructUnion1 {
114 struct { int n1, a1[]; } s1; // { dg-message "declared here" }
115 struct { double n2, a2[]; } s2;
117 } u; // { dg-warning "invalid use" }
120 // The following are invalid and rejected.
121 struct StructUnion2 {
123 struct { int n1, a1[]; } s1; // { dg-error "not at end" }
125 char n3; // { dg-message "next member" }
128 struct StructUnion3 {
130 struct { int n1, a1[]; } s1; // { dg-error "not at end" }
131 struct { double n2, a2[]; } s2;
133 char n3; // { dg-message "next member" }
136 struct StructUnion4 {
138 struct { int n1, a1[]; } s1; // { dg-error "not at end" }
141 struct { double n2, a2[]; } s2;
142 } u2; // { dg-message "next member" }
145 struct StructUnion5 {
148 struct { int n1, a1[]; } s1; // { dg-message "declared here" }
150 union { struct { int n2, a2[]; } s2; } u2;
151 } u; // { dg-warning "invalid use" }
154 struct StructUnion6 {
156 struct { int n1, a1[]; } s1; // { dg-message "declared here" }
157 union { struct { int n2, a2[]; } s2; } u2;
158 } u; // { dg-warning "invalid use" }
161 struct StructUnion7 {
164 struct { double n2, a2[]; } s2; // { dg-message "declared here" }
166 struct { int n1, a1[]; } s1;
167 } u; // { dg-warning "invalid use" }
170 struct StructUnion8 {
174 struct { int n1, a1[]; } s1; // { dg-error "not at end" }
177 struct { double n2, a2[]; } s2;
185 struct { int n1, a1[]; } s1;
188 struct { double n2, a2[]; } s2;
190 } u; } s2; // { dg-message "next member" }
193 struct StructUnion9 { // { dg-message "in the definition" }
197 struct Sx1 { int n1, a1[]; } sx1; // { dg-error "not at end" }
200 struct Sx2 { double n2, a2[]; } sx2;
202 } b1; // { dg-warning "invalid use" }
208 struct Sx3 { int n3, a3[]; } sx3; // { dg-message "declared here" }
210 union D2 { struct Sx4 { double n4, a4[]; } sx4; } d2;
211 } b2; // { dg-warning "invalid use" }
212 } a2; // { dg-message "next member" }
215 // { dg-prune-output "forbids flexible array member" }