summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/finalclasses.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/finalclasses.cxx')
-rw-r--r--compilerplugins/clang/finalclasses.cxx38
1 files changed, 26 insertions, 12 deletions
diff --git a/compilerplugins/clang/finalclasses.cxx b/compilerplugins/clang/finalclasses.cxx
index 4b7a35804719..294e52592a51 100644
--- a/compilerplugins/clang/finalclasses.cxx
+++ b/compilerplugins/clang/finalclasses.cxx
@@ -57,7 +57,11 @@ public:
bool shouldVisitTemplateInstantiations () const { return true; }
+ bool shouldVisitImplicitCode() const { return true; }
+
bool VisitCXXRecordDecl( const CXXRecordDecl* decl);
+private:
+ void checkBase(QualType qt);
};
bool startsWith(const std::string& rStr, const char* pSubStr) {
@@ -81,23 +85,18 @@ bool FinalClasses::VisitCXXRecordDecl(const CXXRecordDecl* decl)
if (ignoreLocation(decl))
return true;
decl = decl->getCanonicalDecl();
- if (!decl->isThisDeclarationADefinition())
+ if (!decl->hasDefinition())
return true;
for (auto it = decl->bases_begin(); it != decl->bases_end(); ++it)
{
const CXXBaseSpecifier spec = *it;
- // need to look through typedefs, hence the getUnqualifiedDesugaredType
- QualType baseType = spec.getType().getDesugaredType(compiler.getASTContext());
- std::string x;
- // so that we get just the template name, excluding the template parameters
- if (baseType->isRecordType())
- x = baseType->getAsCXXRecordDecl()->getQualifiedNameAsString();
- else if (auto templateType = baseType->getAs<TemplateSpecializationType>())
- x = templateType->getTemplateName().getAsTemplateDecl()->getQualifiedNameAsString();
- else
- x = baseType.getAsString();
- inheritedFromSet.insert( x );
+ checkBase(spec.getType());
+ }
+ for (auto it = decl->vbases_begin(); it != decl->vbases_end(); ++it)
+ {
+ const CXXBaseSpecifier spec = *it;
+ checkBase(spec.getType());
}
bool bFoundProtected = false;
@@ -135,6 +134,21 @@ bool FinalClasses::VisitCXXRecordDecl(const CXXRecordDecl* decl)
return true;
}
+void FinalClasses::checkBase(QualType baseType)
+{
+ // need to look through typedefs, hence the getUnqualifiedDesugaredType
+ baseType = baseType.getDesugaredType(compiler.getASTContext());
+ std::string x;
+ // so that we get just the template name, excluding the template parameters
+ if (baseType->isRecordType())
+ x = baseType->getAsCXXRecordDecl()->getQualifiedNameAsString();
+ else if (auto templateType = baseType->getAs<TemplateSpecializationType>())
+ x = templateType->getTemplateName().getAsTemplateDecl()->getQualifiedNameAsString();
+ else
+ x = baseType.getAsString();
+ inheritedFromSet.insert( x );
+}
+
loplugin::Plugin::Registration< FinalClasses > X("finalclasses", false);
}