Fixed #4426 (False positive: Unitialized variable warning when comparing addresses)

This commit is contained in:
Daniel Marjamäki 2012-12-28 12:32:15 +01:00
parent 6770cc80be
commit de2c133f6a
2 changed files with 9 additions and 0 deletions

View File

@ -1417,6 +1417,8 @@ bool CheckUninitVar::isVariableUsage(const Scope* scope, const Token *vartok, bo
// is there something like: ; "*((&var ..expr.. =" => the variable is assigned
if (vartok->previous()->str() == "&") {
const Token *tok2 = vartok->tokAt(-2);
if (tok2 && (tok2->isOp() || tok2->str() == "("))
return false; // address of
if (Token::simpleMatch(tok2,")"))
tok2 = tok2->link()->previous();
while (tok2 && tok2->str() == "(")

View File

@ -2321,6 +2321,13 @@ private:
" return x;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// &
checkUninitVar2("void f() {\n" // #4426 - address of uninitialized variable
" int a,b;\n"
" if (&a == &b);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// #3869 - reference variable