diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 164d8fdd49b..eb76ff1ee76 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -368,13 +368,13 @@ void CheckCondition::comparison() const Token *expr2 = tok->astOperand2(); if (!expr1 || !expr2) continue; - if (expr1->isNumber()) + if (expr1->hasKnownIntValue()) std::swap(expr1,expr2); - if (!expr2->isNumber()) + if (!expr2->hasKnownIntValue()) continue; if (!compareTokenFlags(expr1, expr2, /*macro*/ true)) continue; - const MathLib::bigint num2 = MathLib::toBigNumber(expr2->str()); + const MathLib::bigint num2 = expr2->getKnownIntValue(); if (num2 < 0) continue; if (!Token::Match(expr1,"[&|]")) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 105e0ba9e04..db2f41e6da2 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -503,6 +503,15 @@ class TestCondition : public TestFixture { " if (MACRO_ALL == 0) {}\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + checkP("void f(int i, int j) {\n" // #13360 + " int X = 0x10;\n" + " if ((i & 0xff00) == X) {}\n" + " if (X == (j & 0xff00)) {}\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0xff00) == 0x10' is always false.\n" + "[test.cpp:4]: (style) Expression '(X & 0xff00) == 0x10' is always false.\n", + errout_str()); } #define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__)