diff --git a/include/fmt/format.h b/include/fmt/format.h index 588aa58b..823d1817 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1409,13 +1409,11 @@ inline OutputIt write_padded(OutputIt out, template struct write_int_data { std::size_t size; std::size_t padding; - Char fill; write_int_data(int num_digits, string_view prefix, basic_format_specs& specs) : size(prefix.size() + to_unsigned(num_digits)), - padding(0), - fill(specs.fill[0]) { + padding(0) { if (specs.align == align::numeric) { auto width = to_unsigned(specs.width); if (width > size) { @@ -1425,7 +1423,6 @@ template struct write_int_data { } else if (specs.precision > num_digits) { size = prefix.size() + to_unsigned(specs.precision); padding = to_unsigned(specs.precision - num_digits); - fill = static_cast('0'); } if (specs.align == align::none) specs.align = align::right; } @@ -1442,7 +1439,7 @@ OutputIt write_int(OutputIt out, int num_digits, string_view prefix, return write_padded(out, specs, data.size, [=](iterator it) { if (prefix.size() != 0) it = copy_str(prefix.begin(), prefix.end(), it); - it = std::fill_n(it, data.padding, data.fill); + it = std::fill_n(it, data.padding, static_cast('0')); return f(it); }); } diff --git a/test/format-test.cc b/test/format-test.cc index f9e75d20..66622d7e 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -748,35 +748,7 @@ TEST(FormatterTest, RightAlign) { #if FMT_NUMERIC_ALIGN TEST(FormatterTest, NumericAlign) { - EXPECT_EQ(" 42", format("{0:=4}", 42)); - EXPECT_EQ("+ 42", format("{0:=+4}", 42)); - EXPECT_EQ(" 42", format("{0:=4o}", 042)); - EXPECT_EQ("+ 42", format("{0:=+4o}", 042)); - EXPECT_EQ(" 42", format("{0:=4x}", 0x42)); - EXPECT_EQ("+ 42", format("{0:=+4x}", 0x42)); - EXPECT_EQ("- 42", format("{0:=5}", -42)); - EXPECT_EQ(" 42", format("{0:=5}", 42u)); - EXPECT_EQ("- 42", format("{0:=5}", -42l)); - EXPECT_EQ(" 42", format("{0:=5}", 42ul)); - EXPECT_EQ("- 42", format("{0:=5}", -42ll)); - EXPECT_EQ(" 42", format("{0:=5}", 42ull)); - EXPECT_EQ("- 42.0", format("{0:=7}", -42.0)); - EXPECT_EQ("- 42.0", format("{0:=7}", -42.0l)); - EXPECT_THROW_MSG(format("{0:=5", 'c'), format_error, - "missing '}' in format string"); - EXPECT_THROW_MSG(format("{0:=5}", 'c'), format_error, - "invalid format specifier for char"); - EXPECT_THROW_MSG(format("{0:=5}", "abc"), format_error, - "format specifier requires numeric argument"); - EXPECT_THROW_MSG(format("{0:=8}", reinterpret_cast(0xface)), - format_error, "format specifier requires numeric argument"); - EXPECT_EQ(" 1.0", fmt::format("{:= }", 1.0)); -} - -TEST(FormatToTest, FormatToNonbackInsertIteratorWithSignAndNumericAlignment) { - char buffer[16] = {}; - fmt::format_to(fmt::internal::make_checked(buffer, 16), "{: =+}", 42.0); - EXPECT_STREQ("+42.0", buffer); + EXPECT_EQ("0042", format("{0:=4}", 42)); } #endif