Skip to content

Commit

Permalink
Fix #13153 FN: constStatement (Local Lambda Expression) (#7170)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jan 3, 2025
1 parent 4691aa2 commit 445bc7a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,8 @@ static bool isConstStatement(const Token *tok, bool isNestedBracket = false)
}
return isConstStatement(tok->astOperand2(), /*isNestedBracket*/ !isChained);
}
if (!tok->astParent() && findLambdaEndToken(tok))
return true;
return false;
}

Expand Down Expand Up @@ -2184,6 +2186,8 @@ void CheckOther::constStatementError(const Token *tok, const std::string &type,
msg = "Redundant code: Found unused member access.";
else if (tok->str() == "[" && tok->tokType() == Token::Type::eExtendedOp)
msg = "Redundant code: Found unused array access.";
else if (tok->str() == "[" && !tok->astParent())
msg = "Redundant code: Found unused lambda.";
else if (mSettings->debugwarnings) {
reportError(tok, Severity::debug, "debug", "constStatementError not handled.");
return;
Expand Down
7 changes: 7 additions & 0 deletions test/testincompletestatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,13 @@ class TestIncompleteStatement : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (warning) Redundant code: Found unused array access.\n",
errout_str());

check("void f() {\n" // #13153
" []() {} ();\n"
" []() {};\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found unused lambda.\n",
errout_str());
}

void vardecl() {
Expand Down

0 comments on commit 445bc7a

Please sign in to comment.