summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2015-03-17 11:14:36 +0200
committerNoel Grandin <noel@peralex.com>2015-03-17 11:15:28 +0200
commit5229726b4d4e7d76f410d221f8f8cd8abcfd5a19 (patch)
tree67432ed81e9439fcb98d16c428249f4172014222 /compilerplugins
parentbca6b66358ec26ab6797c72207fdb42066451462 (diff)
loplugin: add Dialog to unusedvariablecheck
so that we find dialog that have been instantiated but not actually executed Change-Id: Ia308e832780627c0a8de71a9d64dabcb3b861a9c
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/unusedvariablecheck.cxx27
1 files changed, 27 insertions, 0 deletions
diff --git a/compilerplugins/clang/unusedvariablecheck.cxx b/compilerplugins/clang/unusedvariablecheck.cxx
index cc3741759a33..0308d9b6150c 100644
--- a/compilerplugins/clang/unusedvariablecheck.cxx
+++ b/compilerplugins/clang/unusedvariablecheck.cxx
@@ -48,6 +48,30 @@ void UnusedVariableCheck::run()
TraverseDecl( compiler.getASTContext().getTranslationUnitDecl());
}
+bool BaseCheckNotDialogSubclass(const CXXRecordDecl *BaseDefinition, void *) {
+ if (BaseDefinition && BaseDefinition->getQualifiedNameAsString().compare("Dialog") == 0) {
+ return false;
+ }
+ return true;
+}
+
+bool isDerivedFromDialog(const CXXRecordDecl *decl) {
+ if (!decl)
+ return false;
+ if (decl->getQualifiedNameAsString() == "Dialog")
+ return true;
+ if (!decl->hasDefinition()) {
+ return false;
+ }
+ if (// not sure what hasAnyDependentBases() does,
+ // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
+ !decl->hasAnyDependentBases() &&
+ !decl->forallBases(BaseCheckNotDialogSubclass, nullptr, true)) {
+ return true;
+ }
+ return false;
+}
+
bool UnusedVariableCheck::VisitVarDecl( const VarDecl* var )
{
if( ignoreLocation( var ))
@@ -83,6 +107,9 @@ bool UnusedVariableCheck::VisitVarDecl( const VarDecl* var )
|| n == "std::list" || n == "std::__debug::list"
|| n == "std::vector" || n == "std::__debug::vector" )
warn_unused = true;
+ // check if this field is derived from Dialog
+ if (!warn_unused && isDerivedFromDialog(type))
+ warn_unused = true;
}
if( warn_unused )
{