From 06ea1a2b538e0ad67f711fec1b9493ca673d0cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 4 Nov 2019 17:59:16 +0100 Subject: [PATCH] Fixed #9312 (FP : variable is assigned a value that is never used (static)) --- lib/checkunusedvar.cpp | 6 +++++- test/testunusedvar.cpp | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 553d84375..ef5cac7b6 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1180,7 +1180,11 @@ void CheckUnusedVar::checkFunctionVariableUsage() if (iteratorToken && iteratorToken->variable() && iteratorToken->variable()->typeEndToken()->str().find("iterator") != std::string::npos) continue; - const Variable *op1Var = tok->astOperand1() ? tok->astOperand1()->variable() : nullptr; + const Token *op1tok = tok->astOperand1(); + while (Token::Match(op1tok, ".|[|*")) + op1tok = op1tok->astOperand1(); + + const Variable *op1Var = op1tok ? op1tok->variable() : nullptr; if (op1Var && op1Var->isReference() && op1Var->nameToken() != tok->astOperand1()) // todo: check references continue; diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 11249d389..1a0d0cf0f 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -3726,6 +3726,13 @@ private: " x++;\n" "}"); ASSERT_EQUALS("", errout.str()); + + functionVariableUsage("void foo(int value) {\n" + " static int array[16] = {0};\n" + " if(array[value]) {}\n" + " array[value] = 1;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void localvarextern() {