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