"flexible array %0 not allowed in otherwise empty struct")
DIAG(ext_flexible_array_in_struct, EXTENSION,
"%0 may not be nested in a struct due to flexible array member")
-DIAG(err_flexible_array_in_array, ERROR,
+DIAG(ext_flexible_array_in_array, EXTENSION,
"%0 may not be used as an array element due to flexible array member")
DIAG(err_flexible_array_init_nonempty, ERROR,
"non-empty initialization of flexible array member inside subobject")
D.setInvalidType(true);
} else if (const RecordType *EltTy = T->getAsRecordType()) {
// If the element type is a struct or union that contains a variadic
- // array, reject it: C99 6.7.2.1p2.
- if (EltTy->getDecl()->hasFlexibleArrayMember()) {
- Diag(DeclType.Loc, diag::err_flexible_array_in_array) << T;
- T = Context.IntTy;
- D.setInvalidType(true);
- }
+ // array, accept it as a GNU extension: C99 6.7.2.1p2.
+ if (EltTy->getDecl()->hasFlexibleArrayMember())
+ Diag(DeclType.Loc, diag::ext_flexible_array_in_array) << T;
} else if (T->isObjCInterfaceType()) {
Diag(DeclType.Loc, diag::warn_objc_array_of_interfaces) << T;
}
-// RUN: clang -fsyntax-only -verify %s
+// RUN: clang -fsyntax-only -pedantic -verify %s
struct one {
int a;
int values[];
struct foo {
int x;
- int y[]; // expected-note 3 {{initialized flexible array member 'y' is here}}
+ int y[]; // expected-note 4 {{initialized flexible array member 'y' is here}}
};
-struct bar { struct foo z; };
+struct bar { struct foo z; }; // expected-warning {{'z' may not be nested in a struct due to flexible array member}}
struct foo a = { 1, { 2, 3, 4 } }; // Valid.
struct bar b = { { 1, { 2, 3, 4 } } }; // expected-error{{non-empty initialization of flexible array member inside subobject}}
-struct bar c = { { 1, { } } }; // Valid.
-struct foo d[1] = { { 1, { 2, 3, 4 } } }; // expected-error{{'struct foo' may not be used as an array element due to flexible array member}}
+struct bar c = { { 1, { } } }; // Valid. \
+ // expected-warning{{use of GNU empty initializer extension}} \
+ // expected-warning{{zero size arrays are an extension}}
+struct foo d[1] = { { 1, { 2, 3, 4 } } }; // expected-warning{{'struct foo' may not be used as an array element due to flexible array member}} \
+ // expected-error{{non-empty initialization of flexible array member inside subobject}}
struct foo desig_foo = { .y = {2, 3, 4} };
-struct bar desig_bar = { .z.y = { } };
+struct bar desig_bar = { .z.y = { } }; // expected-warning{{use of GNU empty initializer extension}} \
+ // expected-warning{{zero size arrays are an extension}}
struct bar desig_bar2 = { .z.y = { 2, 3, 4} }; // expected-error{{non-empty initialization of flexible array member inside subobject}}
struct foo design_foo2 = { .y = 2 }; // expected-error{{flexible array requires brace-enclosed initializer}}
};
struct polygon poly = {
.points[2] = { 1, 2} }; // expected-error{{designator into flexible array member subobject}}
+
+// PR3540
+struct X {
+ int a;
+ int b;
+ char data[];
+};
+
+struct Y {
+ int a:4;
+ int b:4;
+ int c;
+ int d;
+ int e;
+ struct X xs[]; // expected-warning{{'struct X' may not be used as an array element due to flexible array member}}
+};