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() {