Unused variables: better handling of '= %var% ++'. Ticket: #2160
This commit is contained in:
parent
dd4b2b8b46
commit
19f809c9b4
|
@ -1647,11 +1647,21 @@ void CheckOther::functionVariableUsage()
|
|||
else if (Token::Match(tok, "; %var% ;"))
|
||||
variables.readAll(tok->next()->varId());
|
||||
|
||||
else if (Token::Match(tok, "++|-- %var%"))
|
||||
variables.modified(tok->next()->varId());
|
||||
if (Token::Match(tok, "++|-- %var%"))
|
||||
{
|
||||
if (tok->strAt(-1) != ";")
|
||||
variables.use(tok->next()->varId());
|
||||
else
|
||||
variables.modified(tok->next()->varId());
|
||||
}
|
||||
|
||||
else if (Token::Match(tok, "%var% ++|--"))
|
||||
variables.modified(tok->varId());
|
||||
{
|
||||
if (tok->strAt(-1) != ";")
|
||||
variables.use(tok->varId());
|
||||
else
|
||||
variables.modified(tok->varId());
|
||||
}
|
||||
}
|
||||
|
||||
// Check usage of all variables in the current scope..
|
||||
|
|
|
@ -73,6 +73,7 @@ private:
|
|||
TEST_CASE(localvar24); // ticket #1803
|
||||
TEST_CASE(localvar25); // ticket #1729
|
||||
TEST_CASE(localvar26); // ticket #1894
|
||||
TEST_CASE(localvar27); // ticket #2160
|
||||
TEST_CASE(localvaralias1);
|
||||
TEST_CASE(localvaralias2); // ticket #1637
|
||||
TEST_CASE(localvaralias3); // ticket #1639
|
||||
|
@ -1271,6 +1272,15 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvar27() // ticket #2160
|
||||
{
|
||||
functionVariableUsage("void f(struct s *ptr) {\n"
|
||||
" int param = 1;\n"
|
||||
" ptr->param = param++;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvaralias1()
|
||||
{
|
||||
functionVariableUsage("void foo()\n"
|
||||
|
|
Loading…
Reference in New Issue