ValueFlow: Avoid FP when lambda is used
This commit is contained in:
parent
452318dfa4
commit
88c61e8d1e
|
@ -1882,6 +1882,8 @@ static bool valueFlowForward(Token * const startToken,
|
|||
// TODO: handle lambda functions
|
||||
if (tok2->str() == "[" && findLambdaEndToken(tok2)) {
|
||||
Token *lambdaEndToken = const_cast<Token *>(findLambdaEndToken(tok2));
|
||||
if (isVariableChanged(lambdaEndToken->link(), lambdaEndToken, varid, var->isGlobal(), settings, tokenlist->isCPP()))
|
||||
return false;
|
||||
// Dont skip lambdas for lifetime values
|
||||
if (!std::all_of(values.begin(), values.end(), std::mem_fn(&ValueFlow::Value::isLifetimeValue))) {
|
||||
tok2 = lambdaEndToken;
|
||||
|
|
|
@ -1441,6 +1441,15 @@ private:
|
|||
"}\n";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
|
||||
|
||||
code = "int f() {\n"
|
||||
" int x = 1;\n"
|
||||
" dostuff([&]() {\n"
|
||||
" x = y;\n"
|
||||
" });\n"
|
||||
" return x;\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 6U, 1));
|
||||
|
||||
// ?:
|
||||
code = "void f() {\n"
|
||||
" int x = 8;\n"
|
||||
|
|
Loading…
Reference in New Issue