diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index cf082e1dc..63438d5fe 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -1803,6 +1803,8 @@ void CheckCondition::checkCompareValueOutOfTypeRange() continue; if (valueTok->getKnownIntValue() < 0 && valueTok->valueType() && valueTok->valueType()->sign != ValueType::Sign::SIGNED) continue; + if (valueTok->valueType() && valueTok->valueType()->isTypeEqual(typeTok->valueType())) + continue; int bits = 0; switch (typeTok->valueType()->type) { case ValueType::Type::BOOL: diff --git a/test/cfg/googletest.cpp b/test/cfg/googletest.cpp index 26b671e98..37234a703 100644 --- a/test/cfg/googletest.cpp +++ b/test/cfg/googletest.cpp @@ -71,8 +71,8 @@ TEST(Test, warning_in_assert_macros) ASSERT_GE(i, i); unsigned int u = errno; - // cppcheck-suppress [unsignedPositive, compareValueOutOfTypeRangeError] + // cppcheck-suppress [unsignedPositive] ASSERT_GE(u, 0); - // cppcheck-suppress [unsignedLessThanZero, compareValueOutOfTypeRangeError] + // cppcheck-suppress [unsignedLessThanZero] ASSERT_LT(u, 0); } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index b3176619d..5a2fb09a8 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -5258,6 +5258,12 @@ private: "}", &settingsUnix64); ASSERT_EQUALS("", errout.str()); + check("int f(int x) {\n" + " const int i = 0xFFFFFFFF;\n" + " if (x == i) {}\n" + "}", &settingsUnix64); + ASSERT_EQUALS("", errout.str()); + check("void f() {\n" " char c;\n" " if ((c = foo()) != -1) {}\n"