diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 74a2f5c2..e0fd21b1 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -583,7 +583,7 @@ struct chrono_formatter { write_sign(); if (isnan(value)) return write_nan(); uint32_or_64_or_128_t n = to_unsigned( - to_nonnegative_int(value, (std::numeric_limits::max)())); + to_nonnegative_int(value, max_value())); int num_digits = internal::count_digits(n); if (width > num_digits) out = std::fill_n(out, width - num_digits, '0'); out = format_decimal(out, n, num_digits); diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index a2f47689..cef1155f 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -535,8 +535,8 @@ class bigint { bigint& operator*=(uint32_t value) { assert(value > 0); // Verify that the computation doesn't overflow. - constexpr double_bigit max32 = (std::numeric_limits::max)(); - constexpr double_bigit max64 = (std::numeric_limits::max)(); + constexpr double_bigit max32 = max_value(); + constexpr double_bigit max64 = max_value(); static_assert(max32 * max32 <= max64 - max32, ""); bigit carry = 0; const double_bigit wide_value = value; diff --git a/include/fmt/format.h b/include/fmt/format.h index b65c963a..605adb7c 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -213,6 +213,11 @@ inline Dest bit_cast(const Source& source) { return dest; } +// Returns the largest possible value for type T. Same as +// std::numeric_limits::max() but shorter and not affected by the max macro. +template +constexpr T max_value() { return (std::numeric_limits::max)(); } + // An approximation of iterator_t for pre-C++20 systems. template using iterator_t = decltype(std::begin(std::declval())); @@ -1888,7 +1893,7 @@ FMT_CONSTEXPR int parse_nonnegative_int(const Char*& begin, const Char* end, } unsigned value = 0; // Convert to unsigned to prevent a warning. - constexpr unsigned max_int = (std::numeric_limits::max)(); + constexpr unsigned max_int = max_value(); unsigned big = max_int / 10; do { // Check for overflow. @@ -2083,8 +2088,7 @@ template