Fixed #1815 (False positive: uninitialized variable when using ? operator)
This commit is contained in:
parent
b33fb48618
commit
c6888845a0
|
@ -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;
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in New Issue