From b8e405f9f3e00d9385239b0399b90b84d969e1e3 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Fri, 9 May 2014 22:02:28 +0000 Subject: [PATCH] Don't emit -Wnon-virtual-dtor on final classes, since it's not a problem there. 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 | 3 ++- test/SemaCXX/destructor.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 54a332aa99..217588a9c0 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -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()) Diag(dtor ? dtor->getLocation() : Record->getLocation(), diag::warn_non_virtual_dtor) << Context.getRecordType(Record); } diff --git a/test/SemaCXX/destructor.cpp b/test/SemaCXX/destructor.cpp index 7642228c6f..d0a0731c11 100644 --- a/test/SemaCXX/destructor.cpp +++ b/test/SemaCXX/destructor.cpp @@ -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(); -- 2.50.1