Skip to content

Commit 04a8201

Browse files
Fix #14202 FP duplicateExpression with enumerator (danmar#8117)
1 parent 87cc438 commit 04a8201

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/checkother.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,6 +2924,9 @@ void CheckOther::checkDuplicateExpression()
29242924
if (tok->isOp() && tok->astOperand1() && !Token::Match(tok, "+|*|<<|>>|+=|*=|<<=|>>=") && !isInsideLambdaCaptureList(tok)) {
29252925
if (Token::Match(tok, "==|!=|-") && astIsFloat(tok->astOperand1(), true))
29262926
continue;
2927+
if (tok->isArithmeticalOp() &&
2928+
(tok->astOperand1()->isEnumerator() || (tok->astOperand2() && tok->astOperand2()->isEnumerator())))
2929+
continue;
29272930
const bool pointerDereference = (tok->astOperand1() && tok->astOperand1()->isUnaryOp("*")) ||
29282931
(tok->astOperand2() && tok->astOperand2()->isUnaryOp("*"));
29292932
const bool followVar = (!isConstVarExpression(tok) || Token::Match(tok, "%comp%|%oror%|&&")) && !pointerDereference;

test/testother.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class TestOther : public TestFixture {
196196
TEST_CASE(duplicateExpression17); // #12036
197197
TEST_CASE(duplicateExpression18);
198198
TEST_CASE(duplicateExpression19);
199+
TEST_CASE(duplicateExpression20);
199200
TEST_CASE(duplicateExpressionLoop);
200201
TEST_CASE(duplicateValueTernary);
201202
TEST_CASE(duplicateValueTernarySizeof); // #13773
@@ -8010,6 +8011,12 @@ class TestOther : public TestFixture {
80108011
ASSERT_EQUALS("", errout_str());
80118012
}
80128013

8014+
void duplicateExpression20() {
8015+
check("enum { N = 1 };\n" // #14202
8016+
"int f() { return N - 1; }");
8017+
ASSERT_EQUALS("", errout_str());
8018+
}
8019+
80138020
void duplicateExpressionLoop() {
80148021
check("void f() {\n"
80158022
" int a = 1;\n"

0 commit comments

Comments
 (0)