Don't warn for 'x | MACRO' when MACRO is 0 (#4176)

This commit is contained in:
chrchr-github 2022-06-07 21:13:31 +02:00 committed by GitHub
parent 359f6b3680
commit b80d06b69e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -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);
}
}
}

View File

@ -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());
}