summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-03-13 17:24:09 +0100
committerStephan Bergmann <sbergman@redhat.com>2017-03-13 17:24:09 +0100
commit6661bdb076f05427d28a3b069da7ea9ae957cd94 (patch)
tree739c0564990882e1b8a91ec9ac423989b899e3ca /compilerplugins
parente20d9867e29c75dbe4c4c87077d461d3c7d5fd86 (diff)
Minor loplugin:unnecessaryoverride improvement
Change-Id: I3afb31b642a47e767dda0614d223b6b7f22e5d54
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/unnecessaryoverride.cxx18
1 files changed, 8 insertions, 10 deletions
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<RecordType>();
@@ -138,15 +135,16 @@ bool UnnecessaryOverride::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl)
{
const CXXRecordDecl* baseRecordDecl = dyn_cast<CXXRecordDecl>(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