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). llvm-svn: 208449
This commit is contained in:
parent
d0eda92845
commit
04e2e665cb
|
@ -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<FinalAttr>())
|
||||
Diag(dtor ? dtor->getLocation() : Record->getLocation(),
|
||||
diag::warn_non_virtual_dtor) << Context.getRecordType(Record);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue