Fixed #9312 (FP : variable is assigned a value that is never used (static))

This commit is contained in:
Daniel Marjamäki 2019-11-04 17:59:16 +01:00
parent 61286392d9
commit 06ea1a2b53
2 changed files with 12 additions and 1 deletions

View File

@ -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;

View File

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