Fixed #8014 (FP: Uninitialized variable 'f(1,{..});')

This commit is contained in:
Daniel Marjamäki 2017-04-21 22:33:27 +02:00
parent ec6299ea1c
commit 43454936e7
2 changed files with 9 additions and 1 deletions

View File

@ -341,7 +341,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
}
// Unconditional inner scope or try..
if (tok->str() == "{" && Token::Match(tok->previous(), ";|{|}|try")) {
if (tok->str() == "{" && Token::Match(tok->previous(), ",|;|{|}|try")) {
if (checkScopeForVariable(tok->next(), var, possibleInit, noreturn, alloc, membervar))
return true;
tok = tok->link();

View File

@ -2202,6 +2202,14 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("int f() {\n"
" int ret;\n"
" if (a) { ret = 1; }\n"
" else { s=foo(1,{2,3},4); ret = 2; }\n"
" return ret;\n"
"}");
ASSERT_EQUALS("", errout.str());
// conditional initialization
checkUninitVar("void f() {\n"
" int x;\n"