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).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208449
91177308-0d34-0410-b5e6-
96231b3b80d8
// 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);
}
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();