Skip to content

Commit

Permalink
Fix #11998 FN (regression): comparisonError
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jan 4, 2024
1 parent dd869cf commit 2f61114
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,15 @@ class TestCondition : public TestFixture {
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__)
Expand Down

0 comments on commit 2f61114

Please sign in to comment.