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
This commit is contained in:
parent
686b3353aa
commit
7ebe2adfca
@ -2135,8 +2135,8 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
|
|||||||
auto format(std::chrono::time_point<std::chrono::system_clock, Duration> val,
|
auto format(std::chrono::time_point<std::chrono::system_clock, Duration> val,
|
||||||
FormatContext& ctx) const -> decltype(ctx.out()) {
|
FormatContext& ctx) const -> decltype(ctx.out()) {
|
||||||
using period = typename Duration::period;
|
using period = typename Duration::period;
|
||||||
if (period::num != 1 || period::den != 1 ||
|
if constexpr (period::num != 1 || period::den != 1 ||
|
||||||
std::is_floating_point<typename Duration::rep>::value) {
|
std::is_floating_point<typename Duration::rep>::value) {
|
||||||
const auto epoch = val.time_since_epoch();
|
const auto epoch = val.time_since_epoch();
|
||||||
auto subsecs = std::chrono::duration_cast<Duration>(
|
auto subsecs = std::chrono::duration_cast<Duration>(
|
||||||
epoch - std::chrono::duration_cast<std::chrono::seconds>(epoch));
|
epoch - std::chrono::duration_cast<std::chrono::seconds>(epoch));
|
||||||
@ -2153,10 +2153,10 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
|
|||||||
return formatter<std::tm, Char>::do_format(
|
return formatter<std::tm, Char>::do_format(
|
||||||
gmtime(std::chrono::time_point_cast<std::chrono::seconds>(val)), ctx,
|
gmtime(std::chrono::time_point_cast<std::chrono::seconds>(val)), ctx,
|
||||||
&subsecs);
|
&subsecs);
|
||||||
|
} else {
|
||||||
|
return formatter<std::tm, Char>::format(
|
||||||
|
gmtime(std::chrono::time_point_cast<std::chrono::seconds>(val)), ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatter<std::tm, Char>::format(
|
|
||||||
gmtime(std::chrono::time_point_cast<std::chrono::seconds>(val)), ctx);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user