Fixed #2796 (uninitialized and leaving scope)

This commit is contained in:
Daniel Marjamäki 2011-07-25 16:35:30 +02:00
parent 2c6e4c423a
commit 63a0c6ad4a
2 changed files with 18 additions and 1 deletions

View File

@ -160,9 +160,15 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
return;
}
if (tok->str() == "}" || tok->str() == "break")
if (tok->str() == "}")
return;
if (tok->str() == "break")
{
ExecutionPath::bailOut(checks);
return;
}
if (Token::simpleMatch(tok, "while ("))
{
// parse condition

View File

@ -837,6 +837,17 @@ private:
" return x;\n"
"}");
ASSERT_EQUALS("[test.cpp:11]: (error) Uninitialized variable: x\n", errout.str());
// Ticket #2796
checkUninitVar("void foo() {\n"
" while (true) {\n"
" int x;\n"
" if (y) x = 0;\n"
" else break;\n"
" return x;\n" // <- x is initialized
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// switch..