Unused variables: better handling of '= %var% ++'. Ticket: #2160

This commit is contained in:
Daniel Marjamäki 2010-11-02 20:01:12 +01:00
parent dd4b2b8b46
commit 19f809c9b4
2 changed files with 23 additions and 3 deletions

View File

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

View File

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