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
5 changes: 4 additions & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2164,7 +2164,7 @@ static bool isConstStatement(const Token *tok, const Library& library, bool isNe
return isConstStatement(tok->astOperand1(), library) && isConstStatement(tok->astOperand2(), library);
if (Token::Match(tok, "!|~|%cop%") && (tok->astOperand1() || tok->astOperand2()))
return true;
if (Token::simpleMatch(tok->previous(), "sizeof ("))
if (Token::Match(tok->previous(), "sizeof|alignof|noexcept|typeid (") && tok->previous()->isKeyword())
return true;
if (isCPPCast(tok)) {
if (Token::simpleMatch(tok->astOperand1(), "dynamic_cast") && Token::simpleMatch(tok->astOperand1()->linkAt(1)->previous(), "& >"))
Expand Down Expand Up @@ -2299,6 +2299,7 @@ void CheckOther::checkIncompleteStatement()
if (!Token::simpleMatch(tok->astParent(), ";") && !Token::simpleMatch(rtok, ";") &&
!Token::Match(tok->previous(), ";|}|{ %any% ;") &&
!(tok->isCpp() && tok->isCast() && !tok->astParent()) &&
!(!tok->astParent() && Token::Match(tok->previous(), "%name% (") && tok->previous()->isKeyword()) &&
!Token::simpleMatch(tok->tokAt(-2), "for (") &&
!Token::Match(tok->tokAt(-1), "%var% [") &&
!(tok->str() == "," && tok->astParent() && tok->astParent()->isAssignmentOp()))
Expand Down Expand Up @@ -2362,6 +2363,8 @@ void CheckOther::constStatementError(const Token *tok, const std::string &type,
msg = "Redundant code: Found unused lambda.";
else if (Token::Match(tok, "%name%|::"))
msg = "Redundant code: Found unused function.";
else if (Token::Match(tok->previous(), "%name% ("))
msg = "Redundant code: Found unused '" + tok->strAt(-1) + "' expression.";
else if (mSettings->debugwarnings) {
reportError(tok, Severity::debug, "debug", "constStatementError not handled.");
return;
Expand Down
13 changes: 13 additions & 0 deletions test/testincompletestatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,19 @@ class TestIncompleteStatement : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:3:5]: (warning) Redundant code: Found unused lambda. [constStatement]\n",
errout_str());

check("int main() {\n" // #13177
" sizeof(int);\n"
" alignof(long double*);\n"
" noexcept(int());\n"
" typeid(int);\n"
" return(0);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2:11]: (warning) Redundant code: Found unused 'sizeof' expression. [constStatement]\n"
"[test.cpp:3:12]: (warning) Redundant code: Found unused 'alignof' expression. [constStatement]\n"
"[test.cpp:4:13]: (warning) Redundant code: Found unused 'noexcept' expression. [constStatement]\n"
"[test.cpp:5:11]: (warning) Redundant code: Found unused 'typeid' expression. [constStatement]\n",
errout_str());
}

void vardecl() {
Expand Down