Variable usage: Fixed false negative that I introduced when simplifying compound assignments
This commit is contained in:
parent
23d3fd3a5a
commit
558899dc74
|
@ -909,8 +909,14 @@ static int doAssignment(Variables &variables, const Token *tok, bool dereference
|
||||||
{
|
{
|
||||||
int next = 0;
|
int next = 0;
|
||||||
|
|
||||||
|
// a = a + b;
|
||||||
|
if (Token::Match(tok, "%var% = %var% !!;") && tok->str() == tok->strAt(2))
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
// check for aliased variable
|
// check for aliased variable
|
||||||
unsigned int varid1 = tok->varId();
|
const unsigned int varid1 = tok->varId();
|
||||||
Variables::VariableUsage *var1 = variables.find(varid1);
|
Variables::VariableUsage *var1 = variables.find(varid1);
|
||||||
|
|
||||||
if (var1)
|
if (var1)
|
||||||
|
@ -1642,9 +1648,6 @@ void CheckOther::functionVariableUsage()
|
||||||
(Token::Match(tok->next(), "%var%") && !Token::Match(tok->next(), "true|false|new")))
|
(Token::Match(tok->next(), "%var%") && !Token::Match(tok->next(), "true|false|new")))
|
||||||
variables.readAll(tok->next()->varId());
|
variables.readAll(tok->next()->varId());
|
||||||
|
|
||||||
else if (Token::Match(tok, "-=|+=|*=|/=|&=|^= %var%") || Token::Match(tok, "|= %var%"))
|
|
||||||
variables.modified(tok->next()->varId());
|
|
||||||
|
|
||||||
else if (Token::Match(tok, "%var%") && (tok->next()->str() == ")" || isOp(tok->next())))
|
else if (Token::Match(tok, "%var%") && (tok->next()->str() == ")" || isOp(tok->next())))
|
||||||
variables.readAll(tok->varId());
|
variables.readAll(tok->varId());
|
||||||
|
|
||||||
|
|
|
@ -2281,8 +2281,7 @@ private:
|
||||||
" int b = 2;\n"
|
" int b = 2;\n"
|
||||||
" a |= b;\n"
|
" a |= b;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used\n", errout.str());
|
||||||
ASSERT_EQUALS("", errout.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void localvarFor()
|
void localvarFor()
|
||||||
|
|
Loading…
Reference in New Issue