From 9641fc8e43f53b1ae8ed7742017e0a320d75fa8a Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Mon, 31 Jan 2011 17:10:25 +0000 Subject: [PATCH] Only warn for -Wnon-virtual-dtor for public destructors. Thanks to Benjamin Kramer for the hint! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124585 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclCXX.cpp | 4 ++-- test/SemaCXX/destructor.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 89332eae0e..c6ffcc759e 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -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); } diff --git a/test/SemaCXX/destructor.cpp b/test/SemaCXX/destructor.cpp index a86859c62d..ce01b3acc5 100644 --- a/test/SemaCXX/destructor.cpp +++ b/test/SemaCXX/destructor.cpp @@ -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(); +}; } -- 2.40.0