Fixed #3106 (False positive: Uninitialized variable check has inconsistent behavior with ternary operator)
This commit is contained in:
parent
889c407f58
commit
1a7511ed48
|
@ -494,11 +494,11 @@ private:
|
||||||
|
|
||||||
if (tok.str() == "return")
|
if (tok.str() == "return")
|
||||||
{
|
{
|
||||||
// is there assignment in the return statement?
|
// is there assignment or ternary operator in the return statement?
|
||||||
bool assignment = false;
|
bool assignment = false;
|
||||||
for (const Token *tok2 = tok.next(); tok2 && tok2->str() != ";"; tok2 = tok2->next())
|
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;
|
assignment = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -501,6 +501,13 @@ private:
|
||||||
" return x ? 1 : y;\n"
|
" return x ? 1 : y;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: y\n", errout.str());
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue