Skip to content

Commit 4ebb8ea

Browse files
authored
Ignore zero valued enum entries from badBitmaskCheck (danmar#5195)
Usage of zero valued enum entries can be used for documenting purposes and should be ignored just like zeroes expanded from macros.
1 parent 7507d40 commit 4ebb8ea

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/checkcondition.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,15 @@ void CheckCondition::checkBadBitmaskCheck()
317317

318318
const bool isZero1 = (tok->astOperand1()->hasKnownIntValue() && tok->astOperand1()->values().front().intvalue == 0);
319319
const bool isZero2 = (tok->astOperand2()->hasKnownIntValue() && tok->astOperand2()->values().front().intvalue == 0);
320+
if (!isZero1 && !isZero2)
321+
continue;
320322

321-
if ((isZero1 || isZero2) && !tok->isExpandedMacro() && !(isZero1 && tok->astOperand1()->isExpandedMacro()) && !(isZero2 && tok->astOperand2()->isExpandedMacro()))
323+
auto isOperandExpanded = [](const Token *op) {
324+
return op->isExpandedMacro() || op->isEnumerator();
325+
};
326+
if (!tok->isExpandedMacro() &&
327+
!(isZero1 && isOperandExpanded(tok->astOperand1())) &&
328+
!(isZero2 && isOperandExpanded(tok->astOperand2())))
322329
badBitmaskCheckError(tok, /*isNoOp*/ true);
323330
}
324331
}

test/testcondition.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,11 @@ class TestCondition : public TestFixture {
912912
"#endif\n"
913913
" 0;");
914914
ASSERT_EQUALS("", errout.str());
915+
916+
check("enum precedence { PC0, UNARY };\n"
917+
"int x = PC0 | UNARY;\n"
918+
"int y = UNARY | PC0;\n");
919+
ASSERT_EQUALS("", errout.str());
915920
}
916921

917922

0 commit comments

Comments
 (0)