diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 0b8deffc7..eba71bb64 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1882,6 +1882,8 @@ static bool valueFlowForward(Token * const startToken, // TODO: handle lambda functions if (tok2->str() == "[" && findLambdaEndToken(tok2)) { Token *lambdaEndToken = const_cast(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; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 37b3c6ff7..3a4bef722 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -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"