Fixed #2263 (False positive: variable assigned value that is never used)

This commit is contained in:
Daniel Marjamäki 2010-12-02 20:08:05 +01:00
parent 66f0948395
commit 8118e4755a
2 changed files with 17 additions and 2 deletions

View File

@ -1707,7 +1707,11 @@ void CheckOther::functionVariableUsage()
// function
else if (Token::Match(tok, " %var% ("))
{
variables.read(tok->varId());
if (Token::Match(tok->tokAt(2), "%var% ="))
variables.read(tok->tokAt(2)->varId());
}
else if (Token::Match(tok, " %var% ."))
variables.use(tok->varId()); // use = read + write

View File

@ -102,7 +102,8 @@ private:
TEST_CASE(localvarIfElse); // return tmp1 ? tmp2 : tmp3;
TEST_CASE(localvarOpAssign); // a |= b;
TEST_CASE(localvarFor); // for ( ; var; )
TEST_CASE(localvarShift); // 1 >> var
TEST_CASE(localvarShift1); // 1 >> var
TEST_CASE(localvarShift2); // x = x >> 1
TEST_CASE(localvarCast);
TEST_CASE(localvarClass);
TEST_CASE(localvarUnused);
@ -2327,7 +2328,7 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvarShift()
void localvarShift1()
{
functionVariableUsage("int foo()\n"
"{\n"
@ -2337,6 +2338,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvarShift2()
{
functionVariableUsage("int foo()\n"
"{\n"
" int var = 1;\n"
" while (var = var >> 1) { }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvarCast()
{
functionVariableUsage("int foo()\n"