Fixed #2535 (false positive: (style) Variable 'A' is not assigned a value)

This commit is contained in:
Daniel Marjamäki 2011-02-09 19:20:44 +01:00
parent 301f83767e
commit 5175e4ff3f
2 changed files with 13 additions and 2 deletions

View File

@ -1912,8 +1912,6 @@ void CheckOther::functionVariableUsage()
variables.use(tok->next()->varId()); // use = read + write
else if (Token::Match(tok, "[;{}] %var% >>"))
variables.use(tok->next()->varId()); // use = read + write
else if (Token::Match(tok, "[{,] %var% [,}]"))
variables.read(tok->next()->varId());
// function parameter
else if (Token::Match(tok, "[(,] %var% ["))
@ -1932,6 +1930,9 @@ void CheckOther::functionVariableUsage()
variables.read(tok->tokAt(2)->varId());
}
else if (Token::Match(tok, "[{,] %var% [,}]"))
variables.read(tok->next()->varId());
else if (Token::Match(tok, "%var% ."))
variables.use(tok->varId()); // use = read + write

View File

@ -82,6 +82,7 @@ private:
TEST_CASE(localvar32); // ticket #2330
TEST_CASE(localvar33); // ticket #2346
TEST_CASE(localvar34); // ticket #2368
TEST_CASE(localvar35); // ticket #2535
TEST_CASE(localvaralias1);
TEST_CASE(localvaralias2); // ticket #1637
TEST_CASE(localvaralias3); // ticket #1639
@ -1372,6 +1373,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvar35() // ticket #2535
{
functionVariableUsage("void f() {\n"
" int a, b;\n"
" x(1,a,b);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvaralias1()
{
functionVariableUsage("void foo()\n"