Skip to content
Open
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: 3 additions & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2948,7 +2948,9 @@ void CheckOther::checkDuplicateExpression()
while (parent && parent->astParent()) {
parent = parent->astParent();
}
if (parent && parent->previous() && isStaticAssert(*mSettings, parent->previous())) {
if (parent && parent->previous() &&
(isStaticAssert(*mSettings, parent->previous()) ||
Token::simpleMatch(parent->previous(), "assert"))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR, but I wonder if we should have something like entrypoints for this so we can support custom asserts via library files.

continue;
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class TestOther : public TestFixture {
TEST_CASE(duplicateExpression16); // #10569
TEST_CASE(duplicateExpression17); // #12036
TEST_CASE(duplicateExpression18);
TEST_CASE(duplicateExpression19);
TEST_CASE(duplicateExpressionLoop);
TEST_CASE(duplicateValueTernary);
TEST_CASE(duplicateValueTernarySizeof); // #13773
Expand Down Expand Up @@ -7988,6 +7989,14 @@ class TestOther : public TestFixture {
ASSERT_EQUALS("", errout_str());
}

void duplicateExpression19() {
checkP("const int i = 0;\n"
"void f() {\n"
" assert(i == 0);\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void duplicateExpressionLoop() {
check("void f() {\n"
" int a = 1;\n"
Expand Down
Loading