From 8ec2a65b39b9784bda86bf4a07385cc2c63dd098 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 16 Jul 2024 14:19:10 +0200 Subject: [PATCH] Fix #12940 Lambda type const wrongly suggested (#6605) --- lib/symboldatabase.cpp | 2 +- test/testother.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 40c18bdbff6..0ec65c466ca 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3066,7 +3066,7 @@ static bool checkReturns(const Function* function, bool unknown, bool emptyEnabl { if (!function) return false; - if (function->type != Function::eFunction && function->type != Function::eOperatorEqual) + if (function->type != Function::eFunction && function->type != Function::eOperatorEqual && function->type != Function::eLambda) return false; const Token* defStart = function->retDef; if (!defStart) diff --git a/test/testother.cpp b/test/testother.cpp index 48e9aedecc9..52b89b622ee 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3636,6 +3636,16 @@ class TestOther : public TestFixture { " g(r[0] * 2);\n" "}\n"); ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'r' can be declared as reference to const\n", errout_str()); + + check("std::iostream& get();\n" // #12940 + "std::iostream& Fun() {\n" + " auto lam = []() -> std::iostream& {\n" + " std::iostream& ios = get();\n" + " return ios;\n" + " };\n" + " return lam();\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void constParameterCallback() {