From 33efc3c94fb8eea56dbf6067d7957a8cee0c9a8d Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 30 Jul 2020 07:03:11 -0700 Subject: [PATCH] Fix handling of iterators in locale-specific formatting (#1782) --- include/fmt/format.h | 9 +++++---- test/locale-test.cc | 12 ++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index b1ba0713..7213a0da 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -745,9 +745,9 @@ FMT_CONSTEXPR bool is_supported_floating_point(T) { // Smallest of uint32_t, uint64_t, uint128_t that is large enough to // represent all values of T. template -using uint32_or_64_or_128_t = conditional_t< - num_bits() <= 32, uint32_t, - conditional_t() <= 64, uint64_t, uint128_t>>; +using uint32_or_64_or_128_t = + conditional_t() <= 32, uint32_t, + conditional_t() <= 64, uint64_t, uint128_t>>; // Static data is placed in this class template for the header-only config. template struct FMT_EXTERN_TEMPLATE_API basic_data { @@ -1593,7 +1593,8 @@ template struct int_writer { make_checked(p, s.size())); } if (prefix_size != 0) p[-1] = static_cast('-'); - write(out, basic_string_view(buffer.data(), buffer.size()), specs); + out = write(out, basic_string_view(buffer.data(), buffer.size()), + specs); } void on_chr() { *out++ = static_cast(abs_value); } diff --git a/test/locale-test.cc b/test/locale-test.cc index 15a40d99..b2cb8a63 100644 --- a/test/locale-test.cc +++ b/test/locale-test.cc @@ -89,4 +89,16 @@ TEST(LocaleTest, WFormat) { fmt::format(small_grouping_loc, L"{:L}", max_value())); } +TEST(LocaleTest, DoubleFormatter) { + auto loc = std::locale(std::locale(), new special_grouping()); + auto f = fmt::formatter(); + auto parse_ctx = fmt::format_parse_context("L"); + f.parse(parse_ctx); + char buf[10] = {}; + fmt::basic_format_context format_ctx( + buf, {}, fmt::detail::locale_ref(loc)); + *f.format(12345, format_ctx) = 0; + EXPECT_STREQ("12,345", buf); +} + #endif // FMT_STATIC_THOUSANDS_SEPARATOR