Uninitialized variables: Fixed false positives for break/continue/throw

This commit is contained in:
Daniel Marjamäki 2011-12-14 05:45:52 +01:00
parent 40aa326065
commit c7ce87d060
2 changed files with 5 additions and 1 deletions

View File

@ -1105,7 +1105,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
}
}
if (tok->str() == "return")
if (Token::Match(tok, "return|break|continue|throw"))
ret = true;
// variable is seen..

View File

@ -1708,14 +1708,18 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str());
// return, break, continue
checkUninitVar2("void f() {\n"
" int x;\n"
" if (y == 1) { return; }\n"
" if (y == 2) { break; }\n"
" if (y == 3) { continue; }\n"
" else { x = 1; }\n"
" return x;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// exit
checkUninitVar2("void f() {\n"
" int x;\n"
" if (y == 1) { exit(0); }\n"