From 7abc3c01e037a0895a5de1aa424621f7098b285f Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 12 Nov 2020 07:00:11 -0800 Subject: [PATCH] Suppress a useless warning (#2004) --- include/fmt/chrono.h | 3 ++- test/chrono-test.cc | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 73946760..d6a0e97b 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -685,7 +685,8 @@ inline bool isfinite(T value) { // 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 && value <= upper, "invalid value"); + FMT_ASSERT(value >= 0 && to_unsigned(value) <= to_unsigned(upper), + "invalid value"); (void)upper; return static_cast(value); } diff --git a/test/chrono-test.cc b/test/chrono-test.cc index 359001a5..56507449 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -395,4 +395,8 @@ TEST(ChronoTest, SpecialDurations) { "03:33:20"); } +TEST(ChronoTest, UnsignedDuration) { + EXPECT_EQ("42s", fmt::format("{}", std::chrono::duration(42))); +} + #endif // FMT_STATIC_THOUSANDS_SEPARATOR