Fixed #9405 (false positive: (style, inconclusive) Boolean expression 'dqOpen' is used in bitwise operation. Did you mean '&&')
This commit is contained in:
parent
33ec78fe6e
commit
c2f8fb5603
|
@ -95,6 +95,8 @@ void CheckBool::checkBitwiseOnBoolean()
|
||||||
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
|
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
|
||||||
if (tok->isBinaryOp() && (tok->str() == "&" || tok->str() == "|")) {
|
if (tok->isBinaryOp() && (tok->str() == "&" || tok->str() == "|")) {
|
||||||
if (astIsBool(tok->astOperand1()) || astIsBool(tok->astOperand2())) {
|
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();
|
const std::string expression = astIsBool(tok->astOperand1()) ? tok->astOperand1()->expressionString() : tok->astOperand2()->expressionString();
|
||||||
bitwiseOnBooleanError(tok, expression, tok->str() == "&" ? "&&" : "||");
|
bitwiseOnBooleanError(tok, expression, tok->str() == "&" ? "&&" : "||");
|
||||||
}
|
}
|
||||||
|
|
|
@ -858,6 +858,11 @@ private:
|
||||||
" foo(bar, &b);\n"
|
" foo(bar, &b);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f(bool b) {\n" // #9405
|
||||||
|
" class C { void foo(bool &b) {} };\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void incrementBoolean() {
|
void incrementBoolean() {
|
||||||
|
|
Loading…
Reference in New Issue