Skip to content

Commit 176eefc

Browse files
Fix #10655 FN bitwiseOnBoolean with unseen function (danmar#4214)
1 parent de9b65c commit 176eefc

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/checkbool.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ void CheckBool::checkBitwiseOnBoolean()
104104
continue;
105105
if (tok->str() == "|" && !isConvertedToBool(tok) && !(astIsBool(tok->astOperand1()) && astIsBool(tok->astOperand2())))
106106
continue;
107-
if (!isConstExpression(tok->astOperand1(), mSettings->library, true, mTokenizer->isCPP()))
108-
continue;
107+
// first operand will always be evaluated
109108
if (!isConstExpression(tok->astOperand2(), mSettings->library, true, mTokenizer->isCPP()))
110109
continue;
111110
if (tok->astOperand2()->variable() && tok->astOperand2()->variable()->nameToken() == tok->astOperand2())

test/testbool.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,24 @@ class TestBool : public TestFixture {
914914
" return ((p - xm >= d) << 1) | (x - p > d);\n"
915915
"}\n");
916916
ASSERT_EQUALS("", errout.str());
917+
918+
check("int g();\n" // #10655
919+
"void f(bool b) {\n"
920+
" if (g() | b) {}\n"
921+
"}\n");
922+
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'?\n", errout.str());
923+
924+
check("int g();\n"
925+
"void f(bool b) {\n"
926+
" if (b | g()) {}\n"
927+
"}\n");
928+
ASSERT_EQUALS("", errout.str());
929+
930+
check("int g();\n"
931+
"bool f(bool b, bool c) {\n"
932+
" return b | g() | c;\n"
933+
"}\n");
934+
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'?\n", errout.str());
917935
}
918936

919937
void incrementBoolean() {

0 commit comments

Comments
 (0)