Fixed #9405 (false positive: (style, inconclusive) Boolean expression 'dqOpen' is used in bitwise operation. Did you mean '&&')

This commit is contained in:
Daniel Marjamäki 2019-12-20 19:38:30 +01:00
parent 33ec78fe6e
commit c2f8fb5603
2 changed files with 7 additions and 0 deletions

View File

@ -95,6 +95,8 @@ void CheckBool::checkBitwiseOnBoolean()
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
if (tok->isBinaryOp() && (tok->str() == "&" || tok->str() == "|")) {
if (astIsBool(tok->astOperand1()) || astIsBool(tok->astOperand2())) {
if (tok->astOperand2()->variable() && tok->astOperand2()->variable()->nameToken() == tok->astOperand2())
continue;
const std::string expression = astIsBool(tok->astOperand1()) ? tok->astOperand1()->expressionString() : tok->astOperand2()->expressionString();
bitwiseOnBooleanError(tok, expression, tok->str() == "&" ? "&&" : "||");
}

View File

@ -858,6 +858,11 @@ private:
" foo(bar, &b);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(bool b) {\n" // #9405
" class C { void foo(bool &b) {} };\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void incrementBoolean() {