]> granicus.if.org Git - clang/commitdiff
Don't emit -Wnon-virtual-dtor on final classes, since it's not a problem there.
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 9 May 2014 22:02:28 +0000 (22:02 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 9 May 2014 22:02:28 +0000 (22:02 +0000)
The base class is the culprit/risk here - a sealed/final derived class
with virtual functions and a non-virtual dtor can't accidentally be
polymorphically destroyed (if the base class's dtor is protected - which
also suppresses this warning).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208449 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 54a332aa99eb996d93d79ec57b27ecc72f7b24ab..217588a9c0991e7de3c4cfd9230e433ea1a4d231 100644 (file)
@@ -4413,7 +4413,8 @@ void Sema::CheckCompletedCXXClass(CXXRecordDecl *Record) {
   // Warn if the class has virtual methods but non-virtual public destructor.
   if (Record->isPolymorphic() && !Record->isDependentType()) {
     CXXDestructorDecl *dtor = Record->getDestructor();
-    if (!dtor || (!dtor->isVirtual() && dtor->getAccess() == AS_public))
+    if ((!dtor || (!dtor->isVirtual() && dtor->getAccess() == AS_public)) &&
+        !Record->hasAttr<FinalAttr>())
       Diag(dtor ? dtor->getLocation() : Record->getLocation(),
            diag::warn_non_virtual_dtor) << Context.getRecordType(Record);
   }
index 7642228c6f8d41c02587c05b7fdb0ffdf46f637a..d0a0731c11e546c4dba8a68b8556a18af4a1e776 100644 (file)
@@ -195,7 +195,7 @@ struct B { // expected-warning {{has virtual functions but non-virtual destructo
 
 struct D: B {}; // expected-warning {{has virtual functions but non-virtual destructor}}
 
-struct F final: B {}; // expected-warning {{has virtual functions but non-virtual destructor}}
+struct F final : B {};
 
 struct VB {
   virtual void foo();