Skip to content
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
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