From 7650ed04a3d53fe2db6b545858af81c82bce3c21 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 3 May 2024 07:49:16 -0700 Subject: [PATCH] Fix to_nonnegative_int --- include/fmt/chrono.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 6360d903..88dd911e 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1097,9 +1097,10 @@ inline auto to_nonnegative_int(T value, Int upper) -> Int { } template ::value)> inline auto to_nonnegative_int(T value, Int upper) -> Int { - if (value < 0 || value > static_cast(upper)) + auto int_value = static_cast(value); + if (int_value < 0 || value > static_cast(upper)) FMT_THROW(format_error("invalid value")); - return static_cast(value); + return int_value; } constexpr auto pow10(std::uint32_t n) -> long long {