From f68fa72095f85588e98a091f4eae455993e306f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 26 Feb 2017 13:41:49 +0100 Subject: [PATCH] Fixed #7583 (Defect: False positive '(error) Reference to temporary returned') --- lib/checkautovariables.cpp | 7 ++++++- test/testautovariables.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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() {