ValueFlow: Fix FP when lambda is called

This commit is contained in:
Daniel Marjamäki 2018-12-04 18:46:00 +01:00
parent 7c47283e6d
commit f5a94ed300
2 changed files with 13 additions and 3 deletions

View File

@ -1880,10 +1880,10 @@ static bool valueFlowForward(Token * const startToken,
// skip lambda functions
// TODO: handle lambda functions
if (Token::simpleMatch(tok2, "= [")) {
Token *lambdaEndToken = const_cast<Token *>(findLambdaEndToken(tok2->next()));
if (tok2->str() == "[" && findLambdaEndToken(tok2)) {
Token *lambdaEndToken = const_cast<Token *>(findLambdaEndToken(tok2));
// Dont skip lambdas for lifetime values
if (lambdaEndToken && !std::all_of(values.begin(), values.end(), std::mem_fn(&ValueFlow::Value::isLifetimeValue))) {
if (!std::all_of(values.begin(), values.end(), std::mem_fn(&ValueFlow::Value::isLifetimeValue))) {
tok2 = lambdaEndToken;
continue;
}

View File

@ -1431,6 +1431,16 @@ private:
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
code = "void f() {\n"
" int x = 0;\n"
" dostuff([&]() {\n"
" if (x > 0) {}\n"
" x++;\n"
" });\n"
" dosomething(q);\n"
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
// ?:
code = "void f() {\n"
" int x = 8;\n"