Skip to content

Commit 445bc7a

Browse files
Fix #13153 FN: constStatement (Local Lambda Expression) (#7170)
1 parent 4691aa2 commit 445bc7a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/checkother.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,8 @@ static bool isConstStatement(const Token *tok, bool isNestedBracket = false)
20422042
}
20432043
return isConstStatement(tok->astOperand2(), /*isNestedBracket*/ !isChained);
20442044
}
2045+
if (!tok->astParent() && findLambdaEndToken(tok))
2046+
return true;
20452047
return false;
20462048
}
20472049

@@ -2184,6 +2186,8 @@ void CheckOther::constStatementError(const Token *tok, const std::string &type,
21842186
msg = "Redundant code: Found unused member access.";
21852187
else if (tok->str() == "[" && tok->tokType() == Token::Type::eExtendedOp)
21862188
msg = "Redundant code: Found unused array access.";
2189+
else if (tok->str() == "[" && !tok->astParent())
2190+
msg = "Redundant code: Found unused lambda.";
21872191
else if (mSettings->debugwarnings) {
21882192
reportError(tok, Severity::debug, "debug", "constStatementError not handled.");
21892193
return;

test/testincompletestatement.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,13 @@ class TestIncompleteStatement : public TestFixture {
718718
"}\n");
719719
ASSERT_EQUALS("[test.cpp:2]: (warning) Redundant code: Found unused array access.\n",
720720
errout_str());
721+
722+
check("void f() {\n" // #13153
723+
" []() {} ();\n"
724+
" []() {};\n"
725+
"}\n");
726+
ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found unused lambda.\n",
727+
errout_str());
721728
}
722729

723730
void vardecl() {

0 commit comments

Comments
 (0)