Fixed #2796 (uninitialized and leaving scope)
This commit is contained in:
parent
2c6e4c423a
commit
63a0c6ad4a
|
@ -160,9 +160,15 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok->str() == "}" || tok->str() == "break")
|
if (tok->str() == "}")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (tok->str() == "break")
|
||||||
|
{
|
||||||
|
ExecutionPath::bailOut(checks);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Token::simpleMatch(tok, "while ("))
|
if (Token::simpleMatch(tok, "while ("))
|
||||||
{
|
{
|
||||||
// parse condition
|
// parse condition
|
||||||
|
|
|
@ -837,6 +837,17 @@ private:
|
||||||
" return x;\n"
|
" return x;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:11]: (error) Uninitialized variable: x\n", errout.str());
|
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..
|
// switch..
|
||||||
|
|
Loading…
Reference in New Issue