forked from OSchip/llvm-project
Only warn for -Wnon-virtual-dtor for public destructors. Thanks to Benjamin Kramer for the hint!
llvm-svn: 124585
This commit is contained in:
parent
205d5e3a51
commit
33799caf6d
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue