Fix #10655 FN bitwiseOnBoolean with unseen function (#4214)

This commit is contained in:
chrchr-github 2022-06-14 23:08:17 +02:00 committed by GitHub
parent de9b65c737
commit 176eefcbf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -104,8 +104,7 @@ void CheckBool::checkBitwiseOnBoolean()
continue;
if (tok->str() == "|" && !isConvertedToBool(tok) && !(astIsBool(tok->astOperand1()) && astIsBool(tok->astOperand2())))
continue;
if (!isConstExpression(tok->astOperand1(), mSettings->library, true, mTokenizer->isCPP()))
continue;
// first operand will always be evaluated
if (!isConstExpression(tok->astOperand2(), mSettings->library, true, mTokenizer->isCPP()))
continue;
if (tok->astOperand2()->variable() && tok->astOperand2()->variable()->nameToken() == tok->astOperand2())

View File

@ -914,6 +914,24 @@ private:
" return ((p - xm >= d) << 1) | (x - p > d);\n"
"}\n");
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() {