[cfe-commits] r98611 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/CXX/class.access/p4.cpp test/SemaTemplate/virtual-member-functions.cpp

John McCall rjmccall at apple.com
Mon Mar 15 22:36:30 PDT 2010


Author: rjmccall
Date: Tue Mar 16 00:36:30 2010
New Revision: 98611

URL: http://llvm.org/viewvc/llvm-project?rev=98611&view=rev
Log:
Perform access control even for the implicit destructor calls from implicit
destructor definitions.  Remove some code duplication.


Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/CXX/class.access/p4.cpp
    cfe/trunk/test/SemaTemplate/virtual-member-functions.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=98611&r1=98610&r2=98611&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Mar 16 00:36:30 2010
@@ -3819,45 +3819,8 @@
   DeclContext *PreviousContext = CurContext;
   CurContext = Destructor;
 
-  // C++ [class.dtor] p5
-  // Before the implicitly-declared default destructor for a class is
-  // implicitly defined, all the implicitly-declared default destructors
-  // for its base class and its non-static data members shall have been
-  // implicitly defined.
-  for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(),
-       E = ClassDecl->bases_end(); Base != E; ++Base) {
-    CXXRecordDecl *BaseClassDecl
-      = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
-    if (!BaseClassDecl->hasTrivialDestructor()) {
-      if (CXXDestructorDecl *BaseDtor =
-          const_cast<CXXDestructorDecl*>(BaseClassDecl->getDestructor(Context)))
-        MarkDeclarationReferenced(CurrentLocation, BaseDtor);
-      else
-        assert(false &&
-               "DefineImplicitDestructor - missing dtor in a base class");
-    }
-  }
+  MarkBaseAndMemberDestructorsReferenced(Destructor);
 
-  for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(),
-       E = ClassDecl->field_end(); Field != E; ++Field) {
-    QualType FieldType = Context.getCanonicalType((*Field)->getType());
-    if (const ArrayType *Array = Context.getAsArrayType(FieldType))
-      FieldType = Array->getElementType();
-    if (const RecordType *FieldClassType = FieldType->getAs<RecordType>()) {
-      CXXRecordDecl *FieldClassDecl
-        = cast<CXXRecordDecl>(FieldClassType->getDecl());
-      if (!FieldClassDecl->hasTrivialDestructor()) {
-        if (CXXDestructorDecl *FieldDtor =
-            const_cast<CXXDestructorDecl*>(
-                                        FieldClassDecl->getDestructor(Context)))
-          MarkDeclarationReferenced(CurrentLocation, FieldDtor);
-        else
-          assert(false &&
-          "DefineImplicitDestructor - missing dtor in class of a data member");
-      }
-    }
-  }
-  
   // FIXME: If CheckDestructor fails, we should emit a note about where the
   // implicit destructor was needed.
   if (CheckDestructor(Destructor)) {

Modified: cfe/trunk/test/CXX/class.access/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class.access/p4.cpp?rev=98611&r1=98610&r2=98611&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class.access/p4.cpp (original)
+++ cfe/trunk/test/CXX/class.access/p4.cpp Tue Mar 16 00:36:30 2010
@@ -112,8 +112,8 @@
     A local; // expected-error {{variable of type 'test3::A' has private destructor}}
   }
 
-  template <unsigned N> class Base { ~Base(); }; // expected-note 4 {{declared private here}}
-  class Base2 : virtual Base<2> { ~Base2(); }; // expected-note {{declared private here}}
+  template <unsigned N> class Base { ~Base(); }; // expected-note 8 {{declared private here}}
+  class Base2 : virtual Base<2> { ~Base2(); }; // expected-note 2 {{declared private here}}
   class Base3 : virtual Base<3> { public: ~Base3(); };
 
   // These don't cause diagnostics because we don't need the destructor.
@@ -129,6 +129,15 @@
   {
     ~Derived2() {}
   };
+
+  class Derived3 : // expected-error {{inherited virtual base class 'Base<2>' has private destructor}} \
+                   // expected-error {{inherited virtual base class 'Base<3>' has private destructor}}
+    Base<0>,  // expected-error {{base class 'Base<0>' has private destructor}}
+    virtual Base<1>, // expected-error {{base class 'Base<1>' has private destructor}}
+    Base2, // expected-error {{base class 'test3::Base2' has private destructor}}
+    virtual Base3
+  {};
+  Derived3 d3;
 }
 
 // Conversion functions.

Modified: cfe/trunk/test/SemaTemplate/virtual-member-functions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/virtual-member-functions.cpp?rev=98611&r1=98610&r2=98611&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/virtual-member-functions.cpp (original)
+++ cfe/trunk/test/SemaTemplate/virtual-member-functions.cpp Tue Mar 16 00:36:30 2010
@@ -36,10 +36,10 @@
 
 template<typename T>
 struct Derived : Base<T> {
-  virtual void foo() { } // expected-note {{in instantiation of member function 'Base<int>::~Base' requested here}}
+  virtual void foo() { }
 };
 
-template struct Derived<int>;
+template struct Derived<int>; // expected-note {{in instantiation of member function 'Base<int>::~Base' requested here}}
 
 template<typename T>
 struct HasOutOfLineKey {





More information about the cfe-commits mailing list