* Fix #9303 FP uninitvar after lambda expression * Format
This commit is contained in:
parent
f90a93591f
commit
1aff160411
|
@ -365,7 +365,7 @@ static bool isVariableUsed(const Token *tok, const Variable& var)
|
||||||
|
|
||||||
bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var, bool * const possibleInit, bool * const noreturn, Alloc* const alloc, const std::string &membervar, std::map<nonneg int, VariableValue> variableValue)
|
bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var, bool * const possibleInit, bool * const noreturn, Alloc* const alloc, const std::string &membervar, std::map<nonneg int, VariableValue> variableValue)
|
||||||
{
|
{
|
||||||
const bool suppressErrors(possibleInit && *possibleInit); // Assume that this is a variable delaratkon, rather than a fundef
|
const bool suppressErrors(possibleInit && *possibleInit); // Assume that this is a variable declaration, rather than a fundef
|
||||||
const bool printDebug = mSettings->debugwarnings;
|
const bool printDebug = mSettings->debugwarnings;
|
||||||
|
|
||||||
if (possibleInit)
|
if (possibleInit)
|
||||||
|
@ -392,8 +392,8 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unconditional inner scope or try..
|
// Unconditional inner scope, try, lambda, init list
|
||||||
if (tok->str() == "{" && Token::Match(tok->previous(), ",|;|{|}|try")) {
|
if (tok->str() == "{" && Token::Match(tok->previous(), ",|;|{|}|]|try")) {
|
||||||
bool possibleInitInner = false;
|
bool possibleInitInner = false;
|
||||||
if (checkScopeForVariable(tok->next(), var, &possibleInitInner, noreturn, alloc, membervar, variableValue))
|
if (checkScopeForVariable(tok->next(), var, &possibleInitInner, noreturn, alloc, membervar, variableValue))
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -3079,6 +3079,35 @@ private:
|
||||||
" } catch(...) {}\n"
|
" } catch(...) {}\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("void f(bool x) {\n"
|
||||||
|
" bool b;\n"
|
||||||
|
" {\n"
|
||||||
|
" auto g = []{};\n"
|
||||||
|
" b = x;\n"
|
||||||
|
" }\n"
|
||||||
|
" if (b) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("void f(bool x) {\n"
|
||||||
|
" bool b;\n"
|
||||||
|
" {\n"
|
||||||
|
" int i[2]{ 1, 2 };\n"
|
||||||
|
" b = x;\n"
|
||||||
|
" }\n"
|
||||||
|
" if (b) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("void f(bool x) {\n"
|
||||||
|
" bool b;\n"
|
||||||
|
" {\n"
|
||||||
|
" auto g = []{};\n"
|
||||||
|
" }\n"
|
||||||
|
" if (b) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: b\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitvar_funcptr() {
|
void uninitvar_funcptr() {
|
||||||
|
|
Loading…
Reference in New Issue