[cfe-commits] r151441 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/AST/ASTImporter.cpp lib/AST/DeclCXX.cpp lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTWriter.cpp test/PCH/cxx0x-default-delete.cpp test/PCH/cxx11-constexpr.cpp test/SemaCXX/defaulted-private-dtor.cpp

Richard Smith richard-llvm at metafoo.co.uk
Fri Feb 24 23:33:38 PST 2012


Author: rsmith
Date: Sat Feb 25 01:33:38 2012
New Revision: 151441

URL: http://llvm.org/viewvc/llvm-project?rev=151441&view=rev
Log:
Teach CXXRecordDecl::hasIrrelevantDestructor to check the base classes and
data members for deleted or user-provided destructors.

Now it's computed in advance, serialize it, and in passing fix all the other
record DefinitionData flags whose serialization was missing.

Added:
    cfe/trunk/test/PCH/cxx11-constexpr.cpp
Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/lib/AST/ASTImporter.cpp
    cfe/trunk/lib/AST/DeclCXX.cpp
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp
    cfe/trunk/test/PCH/cxx0x-default-delete.cpp
    cfe/trunk/test/SemaCXX/defaulted-private-dtor.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=151441&r1=151440&r2=151441&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Sat Feb 25 01:33:38 2012
@@ -469,6 +469,10 @@
     ///   type (or array thereof), each such class has a trivial destructor.
     bool HasTrivialDestructor : 1;
 
+    /// HasIrrelevantDestructor - True when this class has a destructor with no
+    /// semantic effect.
+    bool HasIrrelevantDestructor : 1;
+
     /// HasNonLiteralTypeFieldsOrBases - True when this class contains at least
     /// one non-static data member or base class of non-literal or volatile
     /// type.
@@ -1145,9 +1149,9 @@
 
   // hasIrrelevantDestructor - Whether this class has a destructor which has no
   // semantic effect. Any such destructor will be trivial, public, defaulted
-  // and not deleted.
+  // and not deleted, and will call only irrelevant destructors.
   bool hasIrrelevantDestructor() const {
-    return hasTrivialDestructor() && !hasUserDeclaredDestructor();
+    return data().HasIrrelevantDestructor;
   }
 
   // hasNonLiteralTypeFieldsOrBases - Whether this class has a non-literal or

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=151441&r1=151440&r2=151441&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Sat Feb 25 01:33:38 2012
@@ -1849,16 +1849,29 @@
     ToData.HasProtectedFields = FromData.HasProtectedFields;
     ToData.HasPublicFields = FromData.HasPublicFields;
     ToData.HasMutableFields = FromData.HasMutableFields;
+    ToData.HasOnlyCMembers = FromData.HasOnlyCMembers;
     ToData.HasTrivialDefaultConstructor = FromData.HasTrivialDefaultConstructor;
     ToData.HasConstexprNonCopyMoveConstructor
       = FromData.HasConstexprNonCopyMoveConstructor;
+    ToData.DefaultedDefaultConstructorIsConstexpr
+      = FromData.DefaultedDefaultConstructorIsConstexpr;
+    ToData.DefaultedCopyConstructorIsConstexpr
+      = FromData.DefaultedCopyConstructorIsConstexpr;
+    ToData.DefaultedMoveConstructorIsConstexpr
+      = FromData.DefaultedMoveConstructorIsConstexpr;
+    ToData.HasConstexprDefaultConstructor
+      = FromData.HasConstexprDefaultConstructor;
+    ToData.HasConstexprCopyConstructor = FromData.HasConstexprCopyConstructor;
+    ToData.HasConstexprMoveConstructor = FromData.HasConstexprMoveConstructor;
     ToData.HasTrivialCopyConstructor = FromData.HasTrivialCopyConstructor;
     ToData.HasTrivialMoveConstructor = FromData.HasTrivialMoveConstructor;
     ToData.HasTrivialCopyAssignment = FromData.HasTrivialCopyAssignment;
     ToData.HasTrivialMoveAssignment = FromData.HasTrivialMoveAssignment;
     ToData.HasTrivialDestructor = FromData.HasTrivialDestructor;
+    ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor;
     ToData.HasNonLiteralTypeFieldsOrBases
       = FromData.HasNonLiteralTypeFieldsOrBases;
+    // ComputedVisibleConversions not imported.
     ToData.UserProvidedDefaultConstructor
       = FromData.UserProvidedDefaultConstructor;
     ToData.DeclaredDefaultConstructor = FromData.DeclaredDefaultConstructor;
@@ -1870,7 +1883,8 @@
     ToData.FailedImplicitMoveConstructor
       = FromData.FailedImplicitMoveConstructor;
     ToData.FailedImplicitMoveAssignment = FromData.FailedImplicitMoveAssignment;
-    
+    ToData.IsLambda = FromData.IsLambda;
+
     SmallVector<CXXBaseSpecifier *, 4> Bases;
     for (CXXRecordDecl::base_class_iterator 
                   Base1 = FromCXX->bases_begin(),

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=151441&r1=151440&r2=151441&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Sat Feb 25 01:33:38 2012
@@ -52,6 +52,7 @@
     HasConstexprMoveConstructor(false), HasTrivialCopyConstructor(true),
     HasTrivialMoveConstructor(true), HasTrivialCopyAssignment(true),
     HasTrivialMoveAssignment(true), HasTrivialDestructor(true),
+    HasIrrelevantDestructor(true),
     HasNonLiteralTypeFieldsOrBases(false), ComputedVisibleConversions(false),
     UserProvidedDefaultConstructor(false), DeclaredDefaultConstructor(false),
     DeclaredCopyConstructor(false), DeclaredMoveConstructor(false),
@@ -284,7 +285,10 @@
     //   have trivial destructors.
     if (!BaseClassDecl->hasTrivialDestructor())
       data().HasTrivialDestructor = false;
-    
+
+    if (!BaseClassDecl->hasIrrelevantDestructor())
+      data().HasIrrelevantDestructor = false;
+
     // A class has an Objective-C object member if... or any of its bases
     // has an Objective-C object member.
     if (BaseClassDecl->hasObjectMember())
@@ -648,7 +652,8 @@
   if (CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(D)) {
     data().DeclaredDestructor = true;
     data().UserDeclaredDestructor = true;
-    
+    data().HasIrrelevantDestructor = false;
+
     // C++ [class]p4: 
     //   A POD-struct is an aggregate class that has [...] no user-defined 
     //   destructor.
@@ -865,6 +870,8 @@
 
         if (!FieldRec->hasTrivialDestructor())
           data().HasTrivialDestructor = false;
+        if (!FieldRec->hasIrrelevantDestructor())
+          data().HasIrrelevantDestructor = false;
         if (FieldRec->hasObjectMember())
           setHasObjectMember(true);
 
@@ -1248,6 +1255,7 @@
     Data.HasTrivialCopyConstructor = false;
     Data.HasTrivialCopyAssignment = false;
     Data.HasTrivialDestructor = false;
+    Data.HasIrrelevantDestructor = false;
   }
   
   // If the class may be abstract (but hasn't been marked as such), check for

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=151441&r1=151440&r2=151441&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Sat Feb 25 01:33:38 2012
@@ -1072,13 +1072,21 @@
   Data.HasProtectedFields = Record[Idx++];
   Data.HasPublicFields = Record[Idx++];
   Data.HasMutableFields = Record[Idx++];
+  Data.HasOnlyCMembers = Record[Idx++];
   Data.HasTrivialDefaultConstructor = Record[Idx++];
   Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
+  Data.DefaultedDefaultConstructorIsConstexpr = Record[Idx++];
+  Data.DefaultedCopyConstructorIsConstexpr = Record[Idx++];
+  Data.DefaultedMoveConstructorIsConstexpr = Record[Idx++];
+  Data.HasConstexprDefaultConstructor = Record[Idx++];
+  Data.HasConstexprCopyConstructor = Record[Idx++];
+  Data.HasConstexprMoveConstructor = Record[Idx++];
   Data.HasTrivialCopyConstructor = Record[Idx++];
   Data.HasTrivialMoveConstructor = Record[Idx++];
   Data.HasTrivialCopyAssignment = Record[Idx++];
   Data.HasTrivialMoveAssignment = Record[Idx++];
   Data.HasTrivialDestructor = Record[Idx++];
+  Data.HasIrrelevantDestructor = Record[Idx++];
   Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
   Data.ComputedVisibleConversions = Record[Idx++];
   Data.UserProvidedDefaultConstructor = Record[Idx++];

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=151441&r1=151440&r2=151441&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Sat Feb 25 01:33:38 2012
@@ -4296,13 +4296,21 @@
   Record.push_back(Data.HasProtectedFields);
   Record.push_back(Data.HasPublicFields);
   Record.push_back(Data.HasMutableFields);
+  Record.push_back(Data.HasOnlyCMembers);
   Record.push_back(Data.HasTrivialDefaultConstructor);
   Record.push_back(Data.HasConstexprNonCopyMoveConstructor);
+  Record.push_back(Data.DefaultedDefaultConstructorIsConstexpr);
+  Record.push_back(Data.DefaultedCopyConstructorIsConstexpr);
+  Record.push_back(Data.DefaultedMoveConstructorIsConstexpr);
+  Record.push_back(Data.HasConstexprDefaultConstructor);
+  Record.push_back(Data.HasConstexprCopyConstructor);
+  Record.push_back(Data.HasConstexprMoveConstructor);
   Record.push_back(Data.HasTrivialCopyConstructor);
   Record.push_back(Data.HasTrivialMoveConstructor);
   Record.push_back(Data.HasTrivialCopyAssignment);
   Record.push_back(Data.HasTrivialMoveAssignment);
   Record.push_back(Data.HasTrivialDestructor);
+  Record.push_back(Data.HasIrrelevantDestructor);
   Record.push_back(Data.HasNonLiteralTypeFieldsOrBases);
   Record.push_back(Data.ComputedVisibleConversions);
   Record.push_back(Data.UserProvidedDefaultConstructor);
@@ -4314,6 +4322,7 @@
   Record.push_back(Data.DeclaredDestructor);
   Record.push_back(Data.FailedImplicitMoveConstructor);
   Record.push_back(Data.FailedImplicitMoveAssignment);
+  // IsLambda bit is already saved.
 
   Record.push_back(Data.NumBases);
   if (Data.NumBases > 0)

Modified: cfe/trunk/test/PCH/cxx0x-default-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx0x-default-delete.cpp?rev=151441&r1=151440&r2=151441&view=diff
==============================================================================
--- cfe/trunk/test/PCH/cxx0x-default-delete.cpp (original)
+++ cfe/trunk/test/PCH/cxx0x-default-delete.cpp Sat Feb 25 01:33:38 2012
@@ -12,6 +12,14 @@
   void bar() = delete; // expected-note{{deleted here}}
 };
 
+struct baz {
+  ~baz() = delete; // expected-note{{deleted here}}
+};
+
+class quux {
+  ~quux() = default; // expected-note{{private here}}
+};
+
 #else
 
 foo::foo() { } // expected-error{{definition of explicitly defaulted default constructor}}
@@ -20,4 +28,7 @@
   f.bar(); // expected-error{{deleted function}}
 }
 
+baz bz; // expected-error{{deleted function}}
+quux qx; // expected-error{{private destructor}}
+
 #endif

Added: cfe/trunk/test/PCH/cxx11-constexpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx11-constexpr.cpp?rev=151441&view=auto
==============================================================================
--- cfe/trunk/test/PCH/cxx11-constexpr.cpp (added)
+++ cfe/trunk/test/PCH/cxx11-constexpr.cpp Sat Feb 25 01:33:38 2012
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -pedantic-errors -std=c++11 -emit-pch %s -o %t
+// RUN: %clang_cc1 -pedantic-errors -std=c++11 -include-pch %t -verify %s
+
+#ifndef HEADER_INCLUDED
+
+#define HEADER_INCLUDED
+
+struct B {
+  B(); // expected-note {{here}}
+  constexpr B(char) {}
+};
+
+struct C { // expected-note {{not an aggregate and has no constexpr constructors}}
+  B b;
+  double d = 0.0;
+};
+
+struct D : B {
+  constexpr D(int n) : B('x'), k(2*n+1) {}
+  int k;
+};
+
+#else
+
+static_assert(D(4).k == 9, "");
+constexpr int f(C c) { return 0; } // expected-error {{not a literal type}}
+constexpr B b; // expected-error {{constant expression}} expected-note {{non-constexpr}}
+
+#endif

Modified: cfe/trunk/test/SemaCXX/defaulted-private-dtor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/defaulted-private-dtor.cpp?rev=151441&r1=151440&r2=151441&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/defaulted-private-dtor.cpp (original)
+++ cfe/trunk/test/SemaCXX/defaulted-private-dtor.cpp Sat Feb 25 01:33:38 2012
@@ -2,7 +2,7 @@
 
 class BadDtor {
   // A private, but nonetheless trivial, destructor.
-  ~BadDtor() = default; // expected-note 9{{here}}
+  ~BadDtor() = default; // expected-note 11{{here}}
   friend class K;
 };
 void f() {
@@ -12,6 +12,15 @@
   BadDtor dd; // expected-error {{private destructor}}
   throw dd; // expected-error {{private destructor}}
 }
+struct V { // expected-note {{here}}
+  V();
+  BadDtor bd; // expected-error {{private destructor}}
+};
+V v; // expected-error {{deleted function}} expected-note {{required here}}
+struct W : BadDtor { // expected-note {{here}} expected-error {{private destructor}}
+  W();
+};
+W w; // expected-error {{deleted function}} expected-note {{required here}}
 struct X : BadDtor { // expected-error {{private destructor}}
   ~X() {}
 };





More information about the cfe-commits mailing list