Remove severity 'experimental' from checkComparisonOfBoolWithBool() (#4097)

* Enable experimental check

* Remove experimental

* Don't compare Booleans using relational operators
This commit is contained in:
chrchr-github 2022-05-10 18:25:13 +02:00 committed by GitHub
parent ad547af6f9
commit e2bb77f990
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 19 deletions

View File

@ -240,11 +240,6 @@ void CheckBool::comparisonOfTwoFuncsReturningBoolError(const Token *tok, const s
void CheckBool::checkComparisonOfBoolWithBool() void CheckBool::checkComparisonOfBoolWithBool()
{ {
// FIXME: This checking is "experimental" because of the false positives
// when self checking lib/tokenize.cpp (#2617)
if (!mSettings->certainty.isEnabled(Certainty::experimental))
return;
if (!mSettings->severity.isEnabled(Severity::style)) if (!mSettings->severity.isEnabled(Severity::style))
return; return;

View File

@ -6670,14 +6670,12 @@ bool Tokenizer::simplifyConditions()
result = (op1 == op2); result = (op1 == op2);
else if (cmp == "!=") else if (cmp == "!=")
result = (op1 != op2); result = (op1 != op2);
else if (cmp == ">=") else if (cmp == ">=" || cmp == "<=")
result = (op1 >= op2); result = true;
else if (cmp == ">") else if (cmp == ">")
result = (op1 > op2); result = (op1 && !op2);
else if (cmp == "<=")
result = (op1 <= op2);
else if (cmp == "<") else if (cmp == "<")
result = (op1 < op2); result = (!op1 && op2);
else else
cmp.clear(); cmp.clear();
} }

View File

@ -78,12 +78,10 @@ private:
} }
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
void check_(const char* file, int line, const char code[], bool experimental = false, const char filename[] = "test.cpp") { void check_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
settings.certainty.setEnabled(Certainty::experimental, experimental);
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
@ -154,7 +152,7 @@ private:
" const int *rmat = n < 4 ? " /* OK */ " const int *rmat = n < 4 ? " /* OK */
" ctx->q_intra_matrix :" " ctx->q_intra_matrix :"
" ctx->q_chroma_intra_matrix;\n" " ctx->q_chroma_intra_matrix;\n"
"}", /*experimental=*/ false, "test.c"); "}", "test.c");
ASSERT_EQUALS("[test.c:3]: (error) Boolean value assigned to pointer.\n", errout.str()); ASSERT_EQUALS("[test.c:3]: (error) Boolean value assigned to pointer.\n", errout.str());
// ticket #6588 (c++ mode) // ticket #6588 (c++ mode)
@ -173,7 +171,7 @@ private:
" char* m1 = compare(a, b) < 0\n" " char* m1 = compare(a, b) < 0\n"
" ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\n" " ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\n"
" : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\n" " : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\n"
"}", /*experimental=*/ false, "test.c"); "}", "test.c");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #7381 // #7381
@ -747,10 +745,8 @@ private:
" else\n" " else\n"
" return false;\n" " return false;\n"
"}\n"; "}\n";
check(code, true); check(code);
ASSERT_EQUALS("[test.cpp:5]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
check(code, false);
ASSERT_EQUALS("", errout.str());
} }
void bitwiseOnBoolean() { // 3062 void bitwiseOnBoolean() { // 3062