Only warn for -Wnon-virtual-dtor for public destructors. Thanks to Benjamin Kramer for the hint!

llvm-svn: 124585
This commit is contained in:
Argyrios Kyrtzidis 2011-01-31 17:10:25 +00:00
parent 205d5e3a51
commit 33799caf6d
2 changed files with 14 additions and 2 deletions

View 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);
}

View 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();
};
}