diff --git a/lib/checkother.cpp b/lib/checkother.cpp index df842260906..53257591273 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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"))) { continue; } } diff --git a/test/testother.cpp b/test/testother.cpp index 6b1ae634d26..a54ee364366 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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 @@ -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"