]> granicus.if.org Git - clang/commitdiff
It's OK for classes to have flexible array elements (but not unions).
authorAnders Carlsson <andersca@mac.com>
Fri, 3 Sep 2010 21:53:49 +0000 (21:53 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 3 Sep 2010 21:53:49 +0000 (21:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113018 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/flexible-array-test.cpp

index 35515183163d38ee5512ead05e018d5ba2f1b334..f5e045a722a0d0dc67ba9bd9cac2816dda6d7891 100644 (file)
@@ -6564,7 +6564,7 @@ void Sema::ActOnFields(Scope* S,
       EnclosingDecl->setInvalidDecl();
       continue;
     } else if (FDTy->isIncompleteArrayType() && i == NumFields - 1 &&
-               Record && Record->isStruct()) {
+               Record && !Record->isUnion()) {
       // Flexible array member.
       if (NumNamedMembers < 1) {
         Diag(FD->getLocation(), diag::err_flexible_array_empty_struct)
index 02e3f83974e2813d8bdd11774de54e8d3ab6c36c..95d8bb1aa4135cca23c74740759fd41e6ff01bed 100644 (file)
@@ -43,3 +43,13 @@ struct X {
    int blah;
    S strings[];        // expected-error {{flexible array member 'strings' of non-POD element type 'S []'}}
 };
+
+class A {
+  int s;
+  char c[];
+};
+
+union B {
+  int s;
+  char c[]; // expected-error {{field has incomplete type 'char []'}}
+};