Fixed #4411 (Variable is assigned a value that is never used.)
This commit is contained in:
parent
8491df31ca
commit
e7aa1ec396
|
@ -776,8 +776,11 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
tok = tok2->next();
|
||||
if (Token::Match(tok, "( %var% )")) // Simple initialization through copy ctor
|
||||
tok = tok->next();
|
||||
else if (Token::Match(tok, "= %var% ;")) // Simple initialization
|
||||
else if (Token::Match(tok, "= %var% ;")) { // Simple initialization
|
||||
tok = tok->next();
|
||||
if (!var->isReference())
|
||||
variables.read(tok->varId(), tok);
|
||||
}
|
||||
else if (var->typeEndToken()->str() == ">") // Be careful with types like std::vector
|
||||
tok = tok->previous();
|
||||
break;
|
||||
|
|
|
@ -1148,6 +1148,14 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str());
|
||||
|
||||
functionVariableUsage("double foo()\n"
|
||||
"{\n"
|
||||
" double i = 0.0;\n"
|
||||
" const double j = i;\n"
|
||||
" return j;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
functionVariableUsage("void foo()\n"
|
||||
"{\n"
|
||||
" A * i;\n"
|
||||
|
|
Loading…
Reference in New Issue