diff --git a/include/fmt/format.h b/include/fmt/format.h index 95604051c0ee..6e80001fce26 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1998,7 +1998,10 @@ auto write_int_localized(OutputIt out, UInt value, unsigned prefix, grouping.count_separators(num_digits)); return write_padded( out, specs, size, size, [&](reserve_iterator it) { - if (prefix != 0) *it++ = static_cast(prefix); + if (prefix != 0) { + char sign = static_cast(prefix); + *it++ = static_cast(sign); + } return grouping.apply(it, string_view(digits, to_unsigned(num_digits))); }); } @@ -2157,7 +2160,8 @@ class counting_iterator { return it; } - FMT_CONSTEXPR friend counting_iterator operator+(counting_iterator it, difference_type n) { + FMT_CONSTEXPR friend counting_iterator operator+(counting_iterator it, + difference_type n) { it.count_ += static_cast(n); return it; } diff --git a/test/xchar-test.cc b/test/xchar-test.cc index fce3e977ebc4..b3da1f556db3 100644 --- a/test/xchar-test.cc +++ b/test/xchar-test.cc @@ -513,4 +513,8 @@ TEST(locale_test, chrono_weekday) { std::locale::global(loc_old); } +TEST(locale_test, sign) { + EXPECT_EQ(fmt::format(std::locale(), L"{:L}", -50), L"-50"); +} + #endif // FMT_STATIC_THOUSANDS_SEPARATOR