Uninitialized variables: Fixed false positives for break/continue/throw
This commit is contained in:
parent
40aa326065
commit
c7ce87d060
|
@ -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;
|
ret = true;
|
||||||
|
|
||||||
// variable is seen..
|
// variable is seen..
|
||||||
|
|
|
@ -1708,14 +1708,18 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str());
|
||||||
|
|
||||||
|
// return, break, continue
|
||||||
checkUninitVar2("void f() {\n"
|
checkUninitVar2("void f() {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
" if (y == 1) { return; }\n"
|
" if (y == 1) { return; }\n"
|
||||||
|
" if (y == 2) { break; }\n"
|
||||||
|
" if (y == 3) { continue; }\n"
|
||||||
" else { x = 1; }\n"
|
" else { x = 1; }\n"
|
||||||
" return x;\n"
|
" return x;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// exit
|
||||||
checkUninitVar2("void f() {\n"
|
checkUninitVar2("void f() {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
" if (y == 1) { exit(0); }\n"
|
" if (y == 1) { exit(0); }\n"
|
||||||
|
|
Loading…
Reference in New Issue