Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress warning C4127 in chrono.h (conditional expression is constant) #2518

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
static_assert(T::is_integer, "To must be integral");

// A and B are both signed, or both unsigned.
if (F::digits <= T::digits) {
if (detail::const_check(F::digits <= T::digits)) {
// From fits in To without any problem.
} else {
// From does not always fit in To, resort to a dynamic check.
Expand Down Expand Up @@ -79,14 +79,14 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
return {};
}
// From is positive. Can it always fit in To?
if (F::digits > T::digits &&
if (detail::const_check(F::digits > T::digits) &&
from > static_cast<From>(detail::max_value<To>())) {
ec = 1;
return {};
}
}

if (!F::is_signed && T::is_signed && F::digits >= T::digits &&
if (detail::const_check(!F::is_signed && T::is_signed && F::digits >= T::digits) &&
from > static_cast<From>(detail::max_value<To>())) {
ec = 1;
return {};
Expand Down Expand Up @@ -243,7 +243,7 @@ To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
}

// multiply with Factor::num without overflow or underflow
if (Factor::num != 1) {
if (detail::const_check(Factor::num != 1)) {
constexpr auto max1 = detail::max_value<IntermediateRep>() /
static_cast<IntermediateRep>(Factor::num);
if (count > max1) {
Expand All @@ -260,7 +260,7 @@ To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
}

// this can't go wrong, right? den>0 is checked earlier.
if (Factor::den != 1) {
if (detail::const_check(Factor::den != 1)) {
using common_t = typename std::common_type<IntermediateRep, intmax_t>::type;
count /= static_cast<common_t>(Factor::den);
}
Expand Down