Fixed #1815 (False positive: uninitialized variable when using ? operator)

This commit is contained in:
Daniel Marjamäki 2010-06-30 08:28:34 +02:00
parent b33fb48618
commit c6888845a0
2 changed files with 11 additions and 1 deletions

View File

@ -2945,7 +2945,7 @@ private:
// check variable usages in rhs/index // check variable usages in rhs/index
for (const Token *tok2 = tok.tokAt(2); tok2; tok2 = tok2->next()) for (const Token *tok2 = tok.tokAt(2); tok2; tok2 = tok2->next())
{ {
if (Token::Match(tok2, ";|)|=")) if (Token::Match(tok2, ";|)|=|?"))
break; break;
if (Token::Match(tok2, "%var% (")) if (Token::Match(tok2, "%var% ("))
break; break;

View File

@ -1681,6 +1681,16 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// ? :
checkUninitVar("static void foo(int v)\n"
"{\n"
" int x;\n"
" if (v > 0)\n"
" v = func(&x);\n"
" x = v <= 0 ? -1 : x;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// while.. // while..
checkUninitVar("int f()\n" checkUninitVar("int f()\n"
"{\n" "{\n"