Uninitialized variables: Fixed false negatives when using ({})

This commit is contained in:
Daniel Marjamäki 2013-11-17 12:11:18 +01:00
parent d342387b95
commit 77e09d72a1
2 changed files with 8 additions and 1 deletions

View File

@ -1649,7 +1649,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool cpp
} }
} }
if (Token::Match(vartok->previous(), "++|--|%cop%")) { if (Token::Match(vartok->previous(), "++|--|?|:|%cop%")) {
if (cpp && vartok->previous()->str() == ">>") { if (cpp && vartok->previous()->str() == ">>") {
// assume that variable is initialized // assume that variable is initialized
return false; return false;

View File

@ -2152,6 +2152,13 @@ private:
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// = ({ .. })
checkUninitVar2("void f() {\n"
" int x = ({ 1 + 2; });\n"
" int y = 1 + (x ? y : y);\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: y\n", errout.str());
// >> => initialization / usage // >> => initialization / usage
{ {
const char code[] = "void f() {\n" const char code[] = "void f() {\n"