diff --git a/lib/checkbool.cpp b/lib/checkbool.cpp index 18fa4625c..cb276188b 100644 --- a/lib/checkbool.cpp +++ b/lib/checkbool.cpp @@ -474,7 +474,8 @@ void CheckBool::returnValueOfFunctionReturningBool(void) if (tok2) tok = tok2; else if (Token::simpleMatch(tok, "return") && tok->astOperand1() && - (tok->astOperand1()->getValueGE(2, mSettings) || tok->astOperand1()->getValueLE(-1, mSettings))) + (tok->astOperand1()->getValueGE(2, mSettings) || tok->astOperand1()->getValueLE(-1, mSettings)) && + !(tok->astOperand1()->astOperand1() && Token::Match(tok->astOperand1(), "&|%or%"))) returnValueBoolError(tok); } } diff --git a/test/testbool.cpp b/test/testbool.cpp index a83a3f306..f9bf6c91c 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -1104,6 +1104,21 @@ private: "return 2;\n" "}\n"); ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout.str()); + + check("bool f(int x) {\n" + " return x & 0x4;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + check("bool f(int x, int y) {\n" + " return x | y;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + check("bool f(int x) {\n" + " return (x & 0x2);\n" + "}"); + ASSERT_EQUALS("", errout.str()); } };