Don't warn for 'x | MACRO' when MACRO is 0 (#4176)
This commit is contained in:
parent
359f6b3680
commit
b80d06b69e
|
@ -311,11 +311,11 @@ void CheckCondition::checkBadBitmaskCheck()
|
|||
if (isBoolean && isTrue)
|
||||
badBitmaskCheckError(tok);
|
||||
|
||||
const bool isNoOp = (tok->astOperand1()->hasKnownIntValue() && tok->astOperand1()->values().front().intvalue == 0) ||
|
||||
(tok->astOperand2()->hasKnownIntValue() && tok->astOperand2()->values().front().intvalue == 0);
|
||||
const bool isZero1 = (tok->astOperand1()->hasKnownIntValue() && tok->astOperand1()->values().front().intvalue == 0);
|
||||
const bool isZero2 = (tok->astOperand2()->hasKnownIntValue() && tok->astOperand2()->values().front().intvalue == 0);
|
||||
|
||||
if (isNoOp && !tok->isExpandedMacro())
|
||||
badBitmaskCheckError(tok, isNoOp);
|
||||
if ((isZero1 || isZero2) && !tok->isExpandedMacro() && !(isZero1 && tok->astOperand1()->isExpandedMacro()) && !(isZero2 && tok->astOperand2()->isExpandedMacro()))
|
||||
badBitmaskCheckError(tok, /*isNoOp*/ true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -899,6 +899,12 @@ private:
|
|||
" return EIGHTTOIS(0);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("#define O_RDONLY 0\n"
|
||||
"void f(const char* s, int* pFd) {\n"
|
||||
" *pFd = open(s, O_RDONLY | O_BINARY, 0);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue