r198983 - Fix "regression" caused by updating our notion of POD to better match the C++11

Richard Smith richard-llvm at metafoo.co.uk
Fri Jan 10 16:53:36 PST 2014


Author: rsmith
Date: Fri Jan 10 18:53:35 2014
New Revision: 198983

URL: http://llvm.org/viewvc/llvm-project?rev=198983&view=rev
Log:
Fix "regression" caused by updating our notion of POD to better match the C++11
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).

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/ARCMT/cxx-checking.mm
    cfe/trunk/test/SemaCXX/flexible-array-test.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=198983&r1=198982&r2=198983&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jan 10 18:53:35 2014
@@ -3970,8 +3970,8 @@ def err_flexible_array_virtual_base : Er
 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>;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=198983&r1=198982&r2=198983&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jan 10 18:53:35 2014
@@ -11994,9 +11994,14 @@ void Sema::ActOnFields(Scope *S, SourceL
         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();

Modified: cfe/trunk/test/ARCMT/cxx-checking.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/cxx-checking.mm?rev=198983&r1=198982&r2=198983&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/cxx-checking.mm (original)
+++ cfe/trunk/test/ARCMT/cxx-checking.mm Fri Jan 10 18:53:35 2014
@@ -80,7 +80,7 @@ int check_non_pod_block1[__is_pod(int (^
 
 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 {

Modified: cfe/trunk/test/SemaCXX/flexible-array-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/flexible-array-test.cpp?rev=198983&r1=198982&r2=198983&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/flexible-array-test.cpp (original)
+++ cfe/trunk/test/SemaCXX/flexible-array-test.cpp Fri Jan 10 18:53:35 2014
@@ -36,14 +36,20 @@ void foo()
 }
 
 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[];
@@ -71,3 +77,14 @@ struct VirtStorage : virtual StorageBase
 };
 
 }
+
+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();
+  }
+};





More information about the cfe-commits mailing list