Fix #11998 FN (regression): comparisonError (#5826)

This commit is contained in:
chrchr-github 2024-01-04 20:58:39 +01:00 committed by GitHub
parent 9aae9aeb25
commit 73187e6e12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -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;

View File

@ -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__)