]> granicus.if.org Git - clang/commitdiff
Only warn for -Wnon-virtual-dtor for public destructors. Thanks to Benjamin Kramer...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 31 Jan 2011 17:10:25 +0000 (17:10 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 31 Jan 2011 17:10:25 +0000 (17:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124585 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/destructor.cpp

index 89332eae0e0ed28af6164f3cae232aec9b08336f..c6ffcc759ecbe18cedd325fb3c2c67fbb672a614 100644 (file)
@@ -2770,10 +2770,10 @@ void Sema::CheckCompletedCXXClass(CXXRecordDecl *Record) {
     }
   }
 
-  // Warn if the class has virtual methods but non-virtual destructor.
+  // Warn if the class has virtual methods but non-virtual public destructor.
   if (Record->isDynamicClass()) {
     CXXDestructorDecl *dtor = Record->getDestructor();
-    if (!(dtor && dtor->isVirtual()))
+    if (!dtor || (!dtor->isVirtual() && dtor->getAccess() == AS_public))
       Diag(dtor ? dtor->getLocation() : Record->getLocation(),
            diag::warn_non_virtual_dtor) << Context.getRecordType(Record);
   }
index a86859c62d92192115e0ccffa4760d4077a4a170..ce01b3acc5a5d1b63eb834cd9ba23c6a0c9b59f9 100644 (file)
@@ -147,4 +147,16 @@ struct B {
 struct S5 : public B {
   virtual void m();
 };
+
+struct S6 {
+  virtual void m();
+private:
+  ~S6();
+};
+
+struct S7 {
+  virtual void m();
+protected:
+  ~S7();
+};
 }