summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/unusedfields.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-11-08 14:56:41 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-11-09 13:57:13 +0100
commit4887f9fe2d5bdbf8d760d88a984439efbdf37d5a (patch)
treeb2baedffc8a2039c15ba6947e196a62b56b13869 /compilerplugins/clang/unusedfields.cxx
parent9b4d079d578dcb5cdc173e44604e078267ea9840 (diff)
loplugin:unusedfields
Change-Id: Ie8a2c6462ddc708140e725847199c8234ab6b592 Reviewed-on: https://gerrit.libreoffice.org/44528 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/unusedfields.cxx')
-rw-r--r--compilerplugins/clang/unusedfields.cxx21
1 files changed, 13 insertions, 8 deletions
diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx
index 22d13f37eddc..7f11d2fb84ab 100644
--- a/compilerplugins/clang/unusedfields.cxx
+++ b/compilerplugins/clang/unusedfields.cxx
@@ -159,11 +159,11 @@ private:
CalleeWrapper calleeFunctionDecl);
llvm::Optional<CalleeWrapper> getCallee(CallExpr const *);
- RecordDecl * insideMoveOrCopyDeclParent;
- RecordDecl * insideStreamOutputOperator;
+ RecordDecl * insideMoveOrCopyDeclParent = nullptr;
+ RecordDecl * insideStreamOutputOperator = nullptr;
// For reasons I do not understand, parentFunctionDecl() is not reliable, so
// we store the parent function on the way down the AST.
- FunctionDecl * insideFunctionDecl;
+ FunctionDecl * insideFunctionDecl = nullptr;
};
void UnusedFields::run()
@@ -361,18 +361,21 @@ bool startswith(const std::string& rStr, const char* pSubStr)
bool UnusedFields::TraverseCXXConstructorDecl(CXXConstructorDecl* cxxConstructorDecl)
{
+ auto copy = insideMoveOrCopyDeclParent;
if (!ignoreLocation(cxxConstructorDecl) && cxxConstructorDecl->isThisDeclarationADefinition())
{
if (cxxConstructorDecl->isCopyOrMoveConstructor())
insideMoveOrCopyDeclParent = cxxConstructorDecl->getParent();
}
bool ret = RecursiveASTVisitor::TraverseCXXConstructorDecl(cxxConstructorDecl);
- insideMoveOrCopyDeclParent = nullptr;
+ insideMoveOrCopyDeclParent = copy;
return ret;
}
bool UnusedFields::TraverseCXXMethodDecl(CXXMethodDecl* cxxMethodDecl)
{
+ auto copy1 = insideMoveOrCopyDeclParent;
+ auto copy2 = insideFunctionDecl;
if (!ignoreLocation(cxxMethodDecl) && cxxMethodDecl->isThisDeclarationADefinition())
{
if (cxxMethodDecl->isCopyAssignmentOperator() || cxxMethodDecl->isMoveAssignmentOperator())
@@ -380,13 +383,15 @@ bool UnusedFields::TraverseCXXMethodDecl(CXXMethodDecl* cxxMethodDecl)
}
insideFunctionDecl = cxxMethodDecl;
bool ret = RecursiveASTVisitor::TraverseCXXMethodDecl(cxxMethodDecl);
- insideMoveOrCopyDeclParent = nullptr;
- insideFunctionDecl = nullptr;
+ insideMoveOrCopyDeclParent = copy1;
+ insideFunctionDecl = copy2;
return ret;
}
bool UnusedFields::TraverseFunctionDecl(FunctionDecl* functionDecl)
{
+ auto copy1 = insideStreamOutputOperator;
+ auto copy2 = insideFunctionDecl;
if (functionDecl->getLocation().isValid() && !ignoreLocation(functionDecl) && functionDecl->isThisDeclarationADefinition())
{
if (functionDecl->getOverloadedOperator() == OO_LessLess
@@ -398,8 +403,8 @@ bool UnusedFields::TraverseFunctionDecl(FunctionDecl* functionDecl)
}
insideFunctionDecl = functionDecl;
bool ret = RecursiveASTVisitor::TraverseFunctionDecl(functionDecl);
- insideStreamOutputOperator = nullptr;
- insideFunctionDecl = nullptr;
+ insideStreamOutputOperator = copy1;
+ insideFunctionDecl = copy2;
return ret;
}