diff --git a/lib/astutils.cpp b/lib/astutils.cpp index fb84b502d..2580e550f 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1108,6 +1108,13 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const // TODO return Result(Result::Type::BAILOUT); + if (const Token *lambdaEndToken = findLambdaEndToken(tok)) { + tok = lambdaEndToken; + const Result lambdaResult = checkRecursive(expr, lambdaEndToken->link()->next(), lambdaEndToken, exprVarIds, local); + if (lambdaResult.type == Result::Type::READ || lambdaResult.type == Result::Type::BAILOUT) + return lambdaResult; + } + if (Token::Match(tok, "return|throw")) { // TODO: Handle these better // Is expr variable used in expression? diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index bdc0e4cec..25cd44aa3 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -181,7 +181,7 @@ private: TEST_CASE(localvarFuncPtr); // #7194 TEST_CASE(localvarAddr); // #7477 TEST_CASE(localvarDelete); - TEST_CASE(localvarReturnCallLambda); // #8941 + TEST_CASE(localvarLambda); // #8941 TEST_CASE(localvarCppInitialization); TEST_CASE(localvarCpp11Initialization); @@ -4233,12 +4233,19 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarReturnCallLambda() { + void localvarLambda() { functionVariableUsage("int foo() {\n" " auto f = []{return 1};\n" " return f();\n" "}"); ASSERT_EQUALS("", errout.str()); + + functionVariableUsage("int foo() {\n" + " auto f = []{return 1};\n" + " auto g = []{return 1};\n" + " return f() + g();\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void localvarCppInitialization() {