Fixed #2805 (false positive: [NotAssigned1.cpp:5]: (style) Variable 'y' is not assigned a value)

This commit is contained in:
Daniel Marjamäki 2011-06-08 19:54:01 +02:00
parent 24061e536b
commit 97d47fa20e
2 changed files with 15 additions and 0 deletions

View File

@ -2278,7 +2278,11 @@ void CheckOther::functionVariableUsage()
for (const Token *tok2 = tok->next(); tok2 && tok2->str() != ";"; tok2 = tok2->next())
{
if (tok2->varId())
{
variables.read(tok2->varId());
if (tok2->next()->isAssignmentOp())
variables.write(tok2->varId());
}
}
}
}

View File

@ -83,6 +83,7 @@ private:
TEST_CASE(localvar33); // ticket #2346
TEST_CASE(localvar34); // ticket #2368
TEST_CASE(localvar35); // ticket #2535
TEST_CASE(localvar36); // ticket #2805
TEST_CASE(localvaralias1);
TEST_CASE(localvaralias2); // ticket #1637
TEST_CASE(localvaralias3); // ticket #1639
@ -1383,6 +1384,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvar36() // ticket #2805
{
functionVariableUsage("int f() {\n"
" int a, b;\n"
" a = 2 * (b = 3);\n"
" return a + b;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvaralias1()
{
functionVariableUsage("void foo()\n"