rules: instead of requiring flexible array members to be POD, require them to
be trivially-destructible. This seems to be the only constraint that actually
matters here (and even then, it's questionable whether this matters).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198983
91177308-0d34-0410-b5e6-
96231b3b80d8
def err_flexible_array_empty_aggregate : Error<
"flexible array member %0 not allowed in otherwise empty "
"%select{struct|interface|union|class|enum}1">;
-def err_flexible_array_has_nonpod_type : Error<
- "flexible array member %0 of non-POD element type %1">;
+def err_flexible_array_has_nontrivial_dtor : Error<
+ "flexible array member %0 of type %1 with non-trivial destruction">;
def ext_flexible_array_in_struct : Extension<
"%0 may not be nested in a struct due to flexible array member">,
InGroup<FlexibleArrayExtensions>;
Diag(FD->getLocation(), diag::ext_c99_flexible_array_member)
<< FD->getDeclName() << Record->getTagKind();
- if (!FD->getType()->isDependentType() &&
- !Context.getBaseElementType(FD->getType()).isPODType(Context)) {
- Diag(FD->getLocation(), diag::err_flexible_array_has_nonpod_type)
+ // If the element type has a non-trivial destructor, we would not
+ // implicitly destroy the elements, so disallow it for now.
+ //
+ // FIXME: GCC allows this. We should probably either implicitly delete
+ // the destructor of the containing class, or just allow this.
+ QualType BaseElem = Context.getBaseElementType(FD->getType());
+ if (!BaseElem->isDependentType() && BaseElem.isDestructedType()) {
+ Diag(FD->getLocation(), diag::err_flexible_array_has_nontrivial_dtor)
<< FD->getDeclName() << FD->getType();
FD->setInvalidDecl();
EnclosingDecl->setInvalidDecl();
struct FlexibleArrayMember0 {
int length;
- id array[]; // expected-error{{flexible array member 'array' of non-POD element type 'id __strong[]'}}
+ id array[]; // expected-error{{flexible array member 'array' of type 'id __strong[]' with non-trivial destruction}}
};
struct FlexibleArrayMember1 {
}
struct S {
- virtual void foo();
+ virtual void foo();
};
struct X {
int blah;
- S strings[]; // expected-error {{flexible array member 'strings' of non-POD element type 'S []'}}
+ S strings[];
};
+S a, b = a;
+S f(X &x) {
+ a = b;
+ return x.strings[0];
+}
+
class A {
int s;
char c[];
};
}
+
+struct NonTrivDtor { ~NonTrivDtor(); };
+// FIXME: It's not clear whether we should disallow examples like this. GCC accepts.
+struct FlexNonTrivDtor {
+ int n;
+ NonTrivDtor ntd[]; // expected-error {{flexible array member 'ntd' of type 'NonTrivDtor []' with non-trivial destruction}}
+ ~FlexNonTrivDtor() {
+ for (int i = n; i != 0; --i)
+ ntd[i-1].~NonTrivDtor();
+ }
+};