Skip to content

Commit

Permalink
Fix MSVC warning in std::chrono::time_point formatter (#3475)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
hmbj and Hans-Martin B. Jensen authored Jun 2, 2023
1 parent 686b335 commit 8abfc14
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -2135,8 +2135,9 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
auto format(std::chrono::time_point<std::chrono::system_clock, Duration> val,
FormatContext& ctx) const -> decltype(ctx.out()) {
using period = typename Duration::period;
if (period::num != 1 || period::den != 1 ||
std::is_floating_point<typename Duration::rep>::value) {
if (detail::const_check(
period::num != 1 || period::den != 1 ||
std::is_floating_point<typename Duration::rep>::value)) {
const auto epoch = val.time_since_epoch();
auto subsecs = std::chrono::duration_cast<Duration>(
epoch - std::chrono::duration_cast<std::chrono::seconds>(epoch));
Expand Down

0 comments on commit 8abfc14

Please sign in to comment.