From e2bb77f990f4fe0472eb0b76c6101804e970134a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 10 May 2022 18:25:13 +0200 Subject: [PATCH] Remove severity 'experimental' from checkComparisonOfBoolWithBool() (#4097) * Enable experimental check * Remove experimental * Don't compare Booleans using relational operators --- lib/checkbool.cpp | 5 ----- lib/tokenize.cpp | 10 ++++------ test/testbool.cpp | 12 ++++-------- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/lib/checkbool.cpp b/lib/checkbool.cpp index a711050fa..f0d58bf60 100644 --- a/lib/checkbool.cpp +++ b/lib/checkbool.cpp @@ -240,11 +240,6 @@ void CheckBool::comparisonOfTwoFuncsReturningBoolError(const Token *tok, const s 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)) return; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index dc5b59769..04dec8914 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6670,14 +6670,12 @@ bool Tokenizer::simplifyConditions() result = (op1 == op2); else if (cmp == "!=") result = (op1 != op2); - else if (cmp == ">=") - result = (op1 >= op2); + else if (cmp == ">=" || cmp == "<=") + result = true; else if (cmp == ">") - result = (op1 > op2); - else if (cmp == "<=") - result = (op1 <= op2); + result = (op1 && !op2); else if (cmp == "<") - result = (op1 < op2); + result = (!op1 && op2); else cmp.clear(); } diff --git a/test/testbool.cpp b/test/testbool.cpp index 009d0d0eb..6f0dbde10 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -78,12 +78,10 @@ private: } #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.. errout.str(""); - settings.certainty.setEnabled(Certainty::experimental, experimental); - // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); @@ -154,7 +152,7 @@ private: " const int *rmat = n < 4 ? " /* OK */ " ctx->q_intra_matrix :" " 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()); // ticket #6588 (c++ mode) @@ -173,7 +171,7 @@ private: " char* m1 = compare(a, b) < 0\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" - "}", /*experimental=*/ false, "test.c"); + "}", "test.c"); ASSERT_EQUALS("", errout.str()); // #7381 @@ -747,10 +745,8 @@ private: " else\n" " return false;\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()); - check(code, false); - ASSERT_EQUALS("", errout.str()); } void bitwiseOnBoolean() { // 3062