Fixed #1103 (false positive: uninitialized variable when using references)

This commit is contained in:
Daniel Marjamäki 2009-12-15 19:50:48 +01:00
parent 368df4c083
commit e03ff727d4
2 changed files with 16 additions and 0 deletions

View File

@ -1335,6 +1335,12 @@ private:
if (Token::simpleMatch(tok.previous(), "="))
{
if (Token::Match(tok.tokAt(-3), "& %var% ="))
{
bailOut(checks);
return &tok;
}
if (!Token::Match(tok.tokAt(-3), ". %var% ="))
{
if (!Token::Match(tok.tokAt(-3), "[;{}] %var% ="))

View File

@ -1258,6 +1258,16 @@ private:
" } = { 0, 0 };\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// references..
checkUninitVar("void f()\n"
"{\n"
" int a;\n"
" int &b = a;\n"
" b = 0;\n"
" int x = a;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}