Fixed #3106 (False positive: Uninitialized variable check has inconsistent behavior with ternary operator)

This commit is contained in:
Daniel Marjamäki 2011-09-20 21:00:05 +02:00
parent 889c407f58
commit 1a7511ed48
2 changed files with 9 additions and 2 deletions

View File

@ -494,11 +494,11 @@ private:
if (tok.str() == "return")
{
// is there assignment in the return statement?
// is there assignment or ternary operator in the return statement?
bool assignment = false;
for (const Token *tok2 = tok.next(); tok2 && tok2->str() != ";"; tok2 = tok2->next())
{
if (tok2->str() == "=" || tok2->str() == ">>")
if (tok2->str() == "=" || tok2->str() == ">>" || tok2->str() == "?")
{
assignment = true;
break;

View File

@ -501,6 +501,13 @@ private:
" return x ? 1 : y;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: y\n", errout.str());
// Ticket #3106 - False positive
checkUninitVar("int f() {\n"
" int i;\n"
" return x(&i) ? i : 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}