From 73187e6e12c32df6fe623324e79c5b133ed668f0 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 4 Jan 2024 20:58:39 +0100 Subject: [PATCH] Fix #11998 FN (regression): comparisonError (#5826) --- lib/checkcondition.cpp | 2 -- test/testcondition.cpp | 9 +++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 8e5e3f134..660cc1ab5 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -417,8 +417,6 @@ void CheckCondition::comparison() void CheckCondition::comparisonError(const Token *tok, const std::string &bitop, MathLib::bigint value1, const std::string &op, MathLib::bigint value2, bool result) { - if (tok && (diag(tok) | diag(tok->astParent()))) - return; std::ostringstream expression; expression << std::hex << "(X " << bitop << " 0x" << value1 << ") " << op << " 0x" << value2; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index b5d3f323e..30cbfd2a5 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -472,6 +472,15 @@ private: ASSERT_EQUALS("",errout.str()); check("void f(int a) {\n assert( (a | 0x07) < 7U );\n}"); ASSERT_EQUALS("",errout.str()); //correct for negative 'a' + + check("void f(int i) {\n" // #11998 + " if ((i & 0x100) == 0x200) {}\n" + " if (0x200 == (i & 0x100)) {}\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The if condition is the same as the previous if condition\n" + "[test.cpp:2]: (style) Expression '(X & 0x100) == 0x200' is always false.\n" + "[test.cpp:3]: (style) Expression '(X & 0x100) == 0x200' is always false.\n", + errout.str()); } #define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__)