Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12940 Lambda type const wrongly suggested #6605

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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