Skip to content

Commit

Permalink
Fix #12940 Lambda type const wrongly suggested (#6605)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jul 16, 2024
1 parent 4e35173 commit 8ec2a65
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 8ec2a65

Please sign in to comment.