From 0cf82f6ad04d96ee795d8e829320daaf32581549 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sat, 19 Feb 2011 19:14:36 +0000 Subject: [PATCH] Teach the virtual-functions-without-virtual-destructor warning to only warn about polymorphic classes (which have virtual functions) rather than dynamic classes (which are polymorphic or have virtual bases). llvm-svn: 126036 --- clang/lib/Sema/SemaDeclCXX.cpp | 2 +- clang/test/SemaCXX/destructor.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index d88d88c37ca1..2e6c4c8ace6e 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -2767,7 +2767,7 @@ void Sema::CheckCompletedCXXClass(CXXRecordDecl *Record) { } // Warn if the class has virtual methods but non-virtual public destructor. - if (Record->isDynamicClass() && !Record->isDependentType()) { + if (Record->isPolymorphic() && !Record->isDependentType()) { CXXDestructorDecl *dtor = Record->getDestructor(); if (!dtor || (!dtor->isVirtual() && dtor->getAccess() == AS_public)) Diag(dtor ? dtor->getLocation() : Record->getLocation(), diff --git a/clang/test/SemaCXX/destructor.cpp b/clang/test/SemaCXX/destructor.cpp index ec437f7101e4..14a4fb891cd3 100644 --- a/clang/test/SemaCXX/destructor.cpp +++ b/clang/test/SemaCXX/destructor.cpp @@ -172,3 +172,8 @@ template class TS2 { // expected-warning {{'nonvirtualdtor::TS2' h TS2 foo; // expected-note {{instantiation}} } + +namespace PR9238 { + class B { public: ~B(); }; + class C : virtual B { public: ~C() { } }; +}