From ff7e73af66169a988f303a5fc9a1cd1ca60f0103 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 26 Sep 2021 07:54:25 -0700 Subject: [PATCH] Always run grisu_gen_digits before fallback_format --- include/fmt/format-inl.h | 8 ++++---- test/compile-fp-test.cc | 10 ++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index e80ae840..4176198c 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -2326,9 +2326,9 @@ FMT_CONSTEXPR20 void fallback_format(Float n, int num_digits, bool binary32, // Generate the given number of digits. exp10 -= num_digits - 1; if (num_digits == 0) { - buf.try_resize(1); denominator *= 10; - buf[0] = add_compare(numerator, numerator, denominator) > 0 ? '1' : '0'; + auto digit = add_compare(numerator, numerator, denominator) > 0 ? '1' : '0'; + buf.push_back(digit); return; } buf.try_resize(to_unsigned(num_digits)); @@ -2407,8 +2407,8 @@ FMT_HEADER_ONLY_CONSTEXPR20 int format_float(T value, int precision, const int max_double_digits = 767; if (precision > max_double_digits) precision = max_double_digits; fixed_handler handler{buf.data(), 0, precision, -cached_exp10, fixed}; - if (!is_constant_evaluated() && - grisu_gen_digits(normalized, 1, exp, handler) != digits::error) { + if (grisu_gen_digits(normalized, 1, exp, handler) != digits::error && + !is_constant_evaluated()) { exp += handler.exp10; buf.try_resize(to_unsigned(handler.size)); fallback = false; diff --git a/test/compile-fp-test.cc b/test/compile-fp-test.cc index 9ffb8e1c..afedc26d 100644 --- a/test/compile-fp-test.cc +++ b/test/compile-fp-test.cc @@ -8,12 +8,10 @@ #include "fmt/compile.h" #include "gmock/gmock.h" -#if defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806 && \ - defined(__cpp_constexpr) && __cpp_constexpr >= 201907 && \ - defined(__cpp_constexpr_dynamic_alloc) && \ - __cpp_constexpr_dynamic_alloc >= 201907 && __cplusplus >= 202002L && \ - !FMT_MSC_VER && \ - !FMT_GCC_VERSION // MSVC & GCC constexpr limits are too low. +#if defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806 && \ + defined(__cpp_constexpr) && __cpp_constexpr >= 201907 && \ + defined(__cpp_constexpr_dynamic_alloc) && \ + __cpp_constexpr_dynamic_alloc >= 201907 && __cplusplus >= 202002L template struct test_string { template constexpr bool operator==(const T& rhs) const noexcept { return fmt::basic_string_view(rhs).compare(buffer) == 0;