From 1c2b201b7d7b8f4516fd5c4b40398358c194af1f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 13 Jan 2026 16:51:55 +0100 Subject: [PATCH 1/2] Update checkother.cpp --- lib/checkother.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 53257591273..1247d97365e 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2924,6 +2924,9 @@ void CheckOther::checkDuplicateExpression() if (tok->isOp() && tok->astOperand1() && !Token::Match(tok, "+|*|<<|>>|+=|*=|<<=|>>=") && !isInsideLambdaCaptureList(tok)) { if (Token::Match(tok, "==|!=|-") && astIsFloat(tok->astOperand1(), true)) continue; + if (tok->isArithmeticalOp() && + (tok->astOperand1()->isEnumerator() || (tok->astOperand2() && tok->astOperand2()->isEnumerator()))) + continue; const bool pointerDereference = (tok->astOperand1() && tok->astOperand1()->isUnaryOp("*")) || (tok->astOperand2() && tok->astOperand2()->isUnaryOp("*")); const bool followVar = (!isConstVarExpression(tok) || Token::Match(tok, "%comp%|%oror%|&&")) && !pointerDereference; From aed0ae50f739710f818f98414a00446e91bd4695 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 13 Jan 2026 16:53:34 +0100 Subject: [PATCH 2/2] Update testother.cpp --- test/testother.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 50581a332c5..7a3f0a176cf 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -196,6 +196,7 @@ class TestOther : public TestFixture { TEST_CASE(duplicateExpression17); // #12036 TEST_CASE(duplicateExpression18); TEST_CASE(duplicateExpression19); + TEST_CASE(duplicateExpression20); TEST_CASE(duplicateExpressionLoop); TEST_CASE(duplicateValueTernary); TEST_CASE(duplicateValueTernarySizeof); // #13773 @@ -8010,6 +8011,12 @@ class TestOther : public TestFixture { ASSERT_EQUALS("", errout_str()); } + void duplicateExpression20() { + check("enum { N = 1 };\n" // #14202 + "int f() { return N - 1; }"); + ASSERT_EQUALS("", errout_str()); + } + void duplicateExpressionLoop() { check("void f() {\n" " int a = 1;\n"