From 0db43cf7feb89f221f642c11b66bcc27043b2b5b Mon Sep 17 00:00:00 2001 From: Federico <55920584+federico-busato@users.noreply.github.com> Date: Mon, 11 Jul 2022 12:29:39 -0700 Subject: [PATCH] Pointless comparison warnings (#2971) Co-authored-by: Federico Busato --- include/fmt/chrono.h | 5 +++-- include/fmt/core.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index c3c52bf5..95a10517 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -203,7 +203,7 @@ To safe_duration_cast(std::chrono::duration from, } const auto min1 = (std::numeric_limits::min)() / Factor::num; - if (count < min1) { + if (!std::is_unsigned::value && count < min1) { ec = 1; return {}; } @@ -1396,7 +1396,8 @@ inline bool isfinite(T) { // Converts value to Int and checks that it's in the range [0, upper). template ::value)> inline Int to_nonnegative_int(T value, Int upper) { - FMT_ASSERT(value >= 0 && to_unsigned(value) <= to_unsigned(upper), + FMT_ASSERT(std::is_unsigned::value || + (value >= 0 && to_unsigned(value) <= to_unsigned(upper)), "invalid value"); (void)upper; return static_cast(value); diff --git a/include/fmt/core.h b/include/fmt/core.h index 8bb73c71..1e8ecad1 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -405,7 +405,7 @@ template auto convert_for_visit(T) -> monostate { return {}; } template FMT_CONSTEXPR auto to_unsigned(Int value) -> typename std::make_unsigned::type { - FMT_ASSERT(value >= 0, "negative value"); + FMT_ASSERT(std::is_unsigned::value || value >= 0, "negative value"); return static_cast::type>(value); }