Removed CheckOther::bitwiseOnBoolean check. The reasons can be seen in my comments in ticket #3062.
This commit is contained in:
parent
494d3af3d1
commit
09109f19f8
|
@ -227,39 +227,6 @@ void CheckOther::clarifyConditionError(const Token *tok, bool assign, bool boolo
|
|||
errmsg);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// if (bool & bool) -> if (bool && bool)
|
||||
// if (bool | bool) -> if (bool || bool)
|
||||
//---------------------------------------------------------------------------
|
||||
void CheckOther::checkBitwiseOnBoolean()
|
||||
{
|
||||
if (!_settings->isEnabled("style"))
|
||||
return;
|
||||
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||
{
|
||||
if (Token::Match(tok, "(|.|return %var% [&|]"))
|
||||
{
|
||||
if (tok->next()->varId())
|
||||
{
|
||||
const Variable *var = _tokenizer->getSymbolDatabase()->getVariableFromVarId(tok->next()->varId());
|
||||
if (var && (var->typeStartToken() == var->typeEndToken()) &&
|
||||
var->typeStartToken()->str() == "bool")
|
||||
{
|
||||
bitwiseOnBooleanError(tok->next(), tok->next()->str(), tok->strAt(2) == "&" ? "&&" : "||");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckOther::bitwiseOnBooleanError(const Token *tok, const std::string &varname, const std::string &op)
|
||||
{
|
||||
reportError(tok, Severity::style, "bitwiseOnBoolean",
|
||||
"Boolean variable '" + varname + "' is used in bitwise operation. Did you mean " + op + " ?");
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------
|
||||
void CheckOther::warningOldStylePointerCast()
|
||||
{
|
||||
|
|
|
@ -102,7 +102,6 @@ public:
|
|||
|
||||
checkOther.checkAssignBoolToPointer();
|
||||
checkOther.checkSignOfUnsignedVariable();
|
||||
checkOther.checkBitwiseOnBoolean();
|
||||
}
|
||||
|
||||
/** @brief Clarify calculation for ".. a * b ? .." */
|
||||
|
@ -226,9 +225,6 @@ public:
|
|||
/** @brief %Check for testing sign of unsigned variable */
|
||||
void checkSignOfUnsignedVariable();
|
||||
|
||||
/** @brief %Check for using bool in bitwise expression */
|
||||
void checkBitwiseOnBoolean();
|
||||
|
||||
// Error messages..
|
||||
void cstyleCastError(const Token *tok);
|
||||
void dangerousUsageStrtolError(const Token *tok);
|
||||
|
@ -265,7 +261,6 @@ public:
|
|||
void assignBoolToPointerError(const Token *tok);
|
||||
void unsignedLessThanZeroError(const Token *tok, const std::string &varname);
|
||||
void unsignedPositiveError(const Token *tok, const std::string &varname);
|
||||
void bitwiseOnBooleanError(const Token *tok, const std::string &varname, const std::string &op);
|
||||
|
||||
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||
{
|
||||
|
@ -314,7 +309,6 @@ public:
|
|||
c.duplicateBreakError(0);
|
||||
c.unsignedLessThanZeroError(0, "varname");
|
||||
c.unsignedPositiveError(0, "varname");
|
||||
c.bitwiseOnBooleanError(0, "varname", "&&");
|
||||
}
|
||||
|
||||
std::string myName() const
|
||||
|
@ -363,7 +357,6 @@ public:
|
|||
"* duplicate break statement\n"
|
||||
"* testing if unsigned variable is negative\n"
|
||||
"* testing is unsigned variable is positive\n"
|
||||
"* using bool in bitwise expression\n"
|
||||
|
||||
// optimisations
|
||||
"* optimisation: detect post increment/decrement\n";
|
||||
|
|
|
@ -121,7 +121,6 @@ private:
|
|||
TEST_CASE(clarifyCondition2); // if (a & b == c)
|
||||
TEST_CASE(clarifyCondition3); // if (! a & b)
|
||||
TEST_CASE(clarifyCondition4); // ticket #3110
|
||||
TEST_CASE(bitwiseOnBoolean); // if (bool & bool)
|
||||
|
||||
TEST_CASE(incorrectStringCompare);
|
||||
|
||||
|
@ -166,7 +165,6 @@ private:
|
|||
checkOther.checkDuplicateIf();
|
||||
checkOther.checkDuplicateBranch();
|
||||
checkOther.checkDuplicateExpression();
|
||||
checkOther.checkBitwiseOnBoolean();
|
||||
|
||||
// Simplify token list..
|
||||
tokenizer.simplifyTokenList();
|
||||
|
@ -2857,63 +2855,6 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void bitwiseOnBoolean() // 3062
|
||||
{
|
||||
check("void f(_Bool a, _Bool b) {\n"
|
||||
" if(a & b) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Boolean variable 'a' is used in bitwise operation. Did you mean && ?\n", errout.str());
|
||||
|
||||
check("void f(_Bool a, _Bool b) {\n"
|
||||
" if(a | b) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Boolean variable 'a' is used in bitwise operation. Did you mean || ?\n", errout.str());
|
||||
|
||||
check("void f(bool a, bool b) {\n"
|
||||
" if(a & b) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Boolean variable 'a' is used in bitwise operation. Did you mean && ?\n", errout.str());
|
||||
|
||||
check("void f(bool a, bool b) {\n"
|
||||
" if(a & !b) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Boolean variable 'a' is used in bitwise operation. Did you mean && ?\n", errout.str());
|
||||
|
||||
check("void f(bool a, bool b) {\n"
|
||||
" if(a | b) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Boolean variable 'a' is used in bitwise operation. Did you mean || ?\n", errout.str());
|
||||
|
||||
check("void f(bool a, bool b) {\n"
|
||||
" if(a | !b) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Boolean variable 'a' is used in bitwise operation. Did you mean || ?\n", errout.str());
|
||||
|
||||
check("bool a, b;\n"
|
||||
"void f() {\n"
|
||||
" if(a & b) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Boolean variable 'a' is used in bitwise operation. Did you mean && ?\n", errout.str());
|
||||
|
||||
check("bool a, b;\n"
|
||||
"void f() {\n"
|
||||
" if(a & !b) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Boolean variable 'a' is used in bitwise operation. Did you mean && ?\n", errout.str());
|
||||
|
||||
check("bool a, b;\n"
|
||||
"void f() {\n"
|
||||
" if(a | b) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Boolean variable 'a' is used in bitwise operation. Did you mean || ?\n", errout.str());
|
||||
|
||||
check("bool a, b;\n"
|
||||
"void f() {\n"
|
||||
" if(a | !b) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Boolean variable 'a' is used in bitwise operation. Did you mean || ?\n", errout.str());
|
||||
}
|
||||
|
||||
void incorrectStringCompare()
|
||||
{
|
||||
check("int f() {\n"
|
||||
|
|
Loading…
Reference in New Issue