diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index c4fc9b80f..92fbec870 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -482,8 +482,13 @@ void CheckAutoVariables::returnReference() // Skip over lambdas tok2 = skipLambda(tok2); + if (!tok2) + break; - if (!tok2 || tok2->str() != "return") + if (tok2->str() == "(") + tok2 = tok2->link(); + + if (tok2->str() != "return") continue; // return.. diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 2865989e7..0d0666d57 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -1048,6 +1048,12 @@ private: "return s_var;\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #7583 + check("Command& foo() {\n" + " return f([]() -> int { return 1; });\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void returnReferenceInnerScope() {