diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 570575b4682..5fc81791bbb 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -1970,6 +1970,8 @@ void CheckCondition::checkCompareValueOutOfTypeRange() continue; if (valueTok->getKnownIntValue() < 0 && valueTok->valueType() && valueTok->valueType()->sign != ValueType::Sign::SIGNED) continue; + if (typeTok->isLiteral()) + continue; std::uint8_t bits = 0; switch (typeTok->valueType()->type) { case ValueType::Type::BOOL: diff --git a/test/cfg/std.c b/test/cfg/std.c index af0b30e03b2..e8dcec1be6c 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -45,7 +45,7 @@ void test_int32_min() { } void test_int64_min() { - // cppcheck-suppress compareValueOutOfTypeRangeError ; tests that INT64_MIN is a signed expression + // TODO cppcheck-suppress knownConditionTrueFalse // #13814 if (INT64_MIN < 0) {} } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 58475896ebe..7a754c2a8e9 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -6375,6 +6375,13 @@ class TestCondition : public TestFixture { ASSERT_EQUALS("[test.cpp:3:14]: (style) Comparing expression of type 'const unsigned int &' against value 4294967295. Condition is always true. [compareValueOutOfTypeRangeError]\n" "[test.cpp:4:13]: (style) Comparing expression of type 'const unsigned int &' against value 4294967295. Condition is always false. [compareValueOutOfTypeRangeError]\n", errout_str()); + + check("void f() {\n" + " long long ll = 1024 * 1024 * 1024;\n" + " if (ll * 8 < INT_MAX) {}\n" + " if (INT_MAX > ll * 8) {}\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void knownConditionCast() {