From 6661bdb076f05427d28a3b069da7ea9ae957cd94 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 13 Mar 2017 17:24:09 +0100 Subject: Minor loplugin:unnecessaryoverride improvement Change-Id: I3afb31b642a47e767dda0614d223b6b7f22e5d54 --- compilerplugins/clang/unnecessaryoverride.cxx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/unnecessaryoverride.cxx b/compilerplugins/clang/unnecessaryoverride.cxx index 166ae654f99f..5102faab7a78 100644 --- a/compilerplugins/clang/unnecessaryoverride.cxx +++ b/compilerplugins/clang/unnecessaryoverride.cxx @@ -114,10 +114,6 @@ bool UnnecessaryOverride::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) // operator to change from being an obsolete feature to being a standard // feature. That difference is not taken into account here. auto cls = methodDecl->getParent(); - if (methodDecl->isVirtual() && cls->getNumBases() == 0) - { - return true; - } if (methodDecl->getAccess() != AS_public) { return true; @@ -131,6 +127,7 @@ bool UnnecessaryOverride::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) // if it's virtual, but it has a base-class with a non-virtual destructor if (methodDecl->isVirtual()) { + bool baseWithVirtualDtor = false; for (auto baseSpecifier = cls->bases_begin(); baseSpecifier != cls->bases_end(); ++baseSpecifier) { const RecordType* baseRecordType = baseSpecifier->getType()->getAs(); @@ -138,15 +135,16 @@ bool UnnecessaryOverride::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) { const CXXRecordDecl* baseRecordDecl = dyn_cast(baseRecordType->getDecl()); if (baseRecordDecl && baseRecordDecl->getDestructor() - && !baseRecordDecl->getDestructor()->isVirtual()) + && baseRecordDecl->getDestructor()->isVirtual()) { - return true; + baseWithVirtualDtor = true; + break; } } - else - { - return true; // dependent base - } + } + if (!baseWithVirtualDtor) + { + return true; } } // corner case -- cgit