Uninitialized variables: Fixed false negatives when using ({})
This commit is contained in:
parent
d342387b95
commit
77e09d72a1
|
@ -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() == ">>") {
|
||||
// assume that variable is initialized
|
||||
return false;
|
||||
|
|
|
@ -2152,6 +2152,13 @@ private:
|
|||
"}");
|
||||
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
|
||||
{
|
||||
const char code[] = "void f() {\n"
|
||||
|
|
Loading…
Reference in New Issue