From fcaaf1d0167088a0cf163ac44c5e5ad375e10a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 28 Dec 2025 15:04:57 +0100 Subject: [PATCH 1/2] add test --- test/testother.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) 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" From 529f1a716c2f2a824772254888f1b7cb5963a7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 28 Dec 2025 15:05:10 +0100 Subject: [PATCH 2/2] fix #14315 --- lib/checkother.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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; } }