parent
de9b65c737
commit
176eefcbf3
|
@ -104,8 +104,7 @@ void CheckBool::checkBitwiseOnBoolean()
|
||||||
continue;
|
continue;
|
||||||
if (tok->str() == "|" && !isConvertedToBool(tok) && !(astIsBool(tok->astOperand1()) && astIsBool(tok->astOperand2())))
|
if (tok->str() == "|" && !isConvertedToBool(tok) && !(astIsBool(tok->astOperand1()) && astIsBool(tok->astOperand2())))
|
||||||
continue;
|
continue;
|
||||||
if (!isConstExpression(tok->astOperand1(), mSettings->library, true, mTokenizer->isCPP()))
|
// first operand will always be evaluated
|
||||||
continue;
|
|
||||||
if (!isConstExpression(tok->astOperand2(), mSettings->library, true, mTokenizer->isCPP()))
|
if (!isConstExpression(tok->astOperand2(), mSettings->library, true, mTokenizer->isCPP()))
|
||||||
continue;
|
continue;
|
||||||
if (tok->astOperand2()->variable() && tok->astOperand2()->variable()->nameToken() == tok->astOperand2())
|
if (tok->astOperand2()->variable() && tok->astOperand2()->variable()->nameToken() == tok->astOperand2())
|
||||||
|
|
|
@ -914,6 +914,24 @@ private:
|
||||||
" return ((p - xm >= d) << 1) | (x - p > d);\n"
|
" return ((p - xm >= d) << 1) | (x - p > d);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("int g();\n" // #10655
|
||||||
|
"void f(bool b) {\n"
|
||||||
|
" if (g() | b) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'?\n", errout.str());
|
||||||
|
|
||||||
|
check("int g();\n"
|
||||||
|
"void f(bool b) {\n"
|
||||||
|
" if (b | g()) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("int g();\n"
|
||||||
|
"bool f(bool b, bool c) {\n"
|
||||||
|
" return b | g() | c;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'?\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void incrementBoolean() {
|
void incrementBoolean() {
|
||||||
|
|
Loading…
Reference in New Issue