From 7ebe2adfca1ab236d3c70f0d58cf7bf0552cac13 Mon Sep 17 00:00:00 2001 From: "Hans-Martin B. Jensen" Date: Fri, 2 Jun 2023 14:26:03 +0200 Subject: [PATCH] Fix MSVC warning in std::chrono::time_point formatter The condition is constexpr causing MSVC level 4 warning: warning C4127: conditional expression is constant Changed the code to eliminate the warning --- include/fmt/chrono.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 74fc8485..674d2cfc 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2135,8 +2135,8 @@ struct formatter, auto format(std::chrono::time_point val, FormatContext& ctx) const -> decltype(ctx.out()) { using period = typename Duration::period; - if (period::num != 1 || period::den != 1 || - std::is_floating_point::value) { + if constexpr (period::num != 1 || period::den != 1 || + std::is_floating_point::value) { const auto epoch = val.time_since_epoch(); auto subsecs = std::chrono::duration_cast( epoch - std::chrono::duration_cast(epoch)); @@ -2153,10 +2153,10 @@ struct formatter, return formatter::do_format( gmtime(std::chrono::time_point_cast(val)), ctx, &subsecs); + } else { + return formatter::format( + gmtime(std::chrono::time_point_cast(val)), ctx); } - - return formatter::format( - gmtime(std::chrono::time_point_cast(val)), ctx); } };