Skip to content

Commit e2bb77f

Browse files
Remove severity 'experimental' from checkComparisonOfBoolWithBool() (cppcheck-opensource#4097)
* Enable experimental check * Remove experimental * Don't compare Booleans using relational operators
1 parent ad547af commit e2bb77f

3 files changed

Lines changed: 8 additions & 19 deletions

File tree

lib/checkbool.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,6 @@ void CheckBool::comparisonOfTwoFuncsReturningBoolError(const Token *tok, const s
240240

241241
void CheckBool::checkComparisonOfBoolWithBool()
242242
{
243-
// FIXME: This checking is "experimental" because of the false positives
244-
// when self checking lib/tokenize.cpp (#2617)
245-
if (!mSettings->certainty.isEnabled(Certainty::experimental))
246-
return;
247-
248243
if (!mSettings->severity.isEnabled(Severity::style))
249244
return;
250245

lib/tokenize.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6670,14 +6670,12 @@ bool Tokenizer::simplifyConditions()
66706670
result = (op1 == op2);
66716671
else if (cmp == "!=")
66726672
result = (op1 != op2);
6673-
else if (cmp == ">=")
6674-
result = (op1 >= op2);
6673+
else if (cmp == ">=" || cmp == "<=")
6674+
result = true;
66756675
else if (cmp == ">")
6676-
result = (op1 > op2);
6677-
else if (cmp == "<=")
6678-
result = (op1 <= op2);
6676+
result = (op1 && !op2);
66796677
else if (cmp == "<")
6680-
result = (op1 < op2);
6678+
result = (!op1 && op2);
66816679
else
66826680
cmp.clear();
66836681
}

test/testbool.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,10 @@ class TestBool : public TestFixture {
7878
}
7979

8080
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
81-
void check_(const char* file, int line, const char code[], bool experimental = false, const char filename[] = "test.cpp") {
81+
void check_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
8282
// Clear the error buffer..
8383
errout.str("");
8484

85-
settings.certainty.setEnabled(Certainty::experimental, experimental);
86-
8785
// Tokenize..
8886
Tokenizer tokenizer(&settings, this);
8987
std::istringstream istr(code);
@@ -154,7 +152,7 @@ class TestBool : public TestFixture {
154152
" const int *rmat = n < 4 ? " /* OK */
155153
" ctx->q_intra_matrix :"
156154
" ctx->q_chroma_intra_matrix;\n"
157-
"}", /*experimental=*/ false, "test.c");
155+
"}", "test.c");
158156
ASSERT_EQUALS("[test.c:3]: (error) Boolean value assigned to pointer.\n", errout.str());
159157

160158
// ticket #6588 (c++ mode)
@@ -173,7 +171,7 @@ class TestBool : public TestFixture {
173171
" char* m1 = compare(a, b) < 0\n"
174172
" ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\n"
175173
" : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\n"
176-
"}", /*experimental=*/ false, "test.c");
174+
"}", "test.c");
177175
ASSERT_EQUALS("", errout.str());
178176

179177
// #7381
@@ -747,10 +745,8 @@ class TestBool : public TestFixture {
747745
" else\n"
748746
" return false;\n"
749747
"}\n";
750-
check(code, true);
748+
check(code);
751749
ASSERT_EQUALS("[test.cpp:5]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str());
752-
check(code, false);
753-
ASSERT_EQUALS("", errout.str());
754750
}
755751

756752
void bitwiseOnBoolean() { // 3062

0 commit comments

Comments
 (0)