Skip to content

Commit c2f8fb5

Browse files
committed
Fixed #9405 (false positive: (style, inconclusive) Boolean expression 'dqOpen' is used in bitwise operation. Did you mean '&&')
1 parent 33ec78f commit c2f8fb5

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

lib/checkbool.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ void CheckBool::checkBitwiseOnBoolean()
9595
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
9696
if (tok->isBinaryOp() && (tok->str() == "&" || tok->str() == "|")) {
9797
if (astIsBool(tok->astOperand1()) || astIsBool(tok->astOperand2())) {
98+
if (tok->astOperand2()->variable() && tok->astOperand2()->variable()->nameToken() == tok->astOperand2())
99+
continue;
98100
const std::string expression = astIsBool(tok->astOperand1()) ? tok->astOperand1()->expressionString() : tok->astOperand2()->expressionString();
99101
bitwiseOnBooleanError(tok, expression, tok->str() == "&" ? "&&" : "||");
100102
}

test/testbool.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,11 @@ class TestBool : public TestFixture {
858858
" foo(bar, &b);\n"
859859
"}");
860860
ASSERT_EQUALS("", errout.str());
861+
862+
check("void f(bool b) {\n" // #9405
863+
" class C { void foo(bool &b) {} };\n"
864+
"}");
865+
ASSERT_EQUALS("", errout.str());
861866
}
862867

863868
void incrementBoolean() {

0 commit comments

Comments
 (0)