From 8abfc145be94bfe3dc4381fe18eef467b305f5f1 Mon Sep 17 00:00:00 2001 From: "Hans-Martin B. Jensen" <32485905+hmbj@users.noreply.github.com> Date: Fri, 2 Jun 2023 17:40:34 +0200 Subject: [PATCH] Fix MSVC warning in std::chrono::time_point formatter (#3475) * 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 * Use detail::const_check * Review: revert else condition --------- Co-authored-by: Hans-Martin B. Jensen --- 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 74fc8485..96a215da 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2135,8 +2135,9 @@ 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 (detail::const_check( + 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));