diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 6d014fcd..951825ed 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -257,7 +257,10 @@ class printf_arg_formatter : public detail::arg_formatter_base { return (*this)(static_cast(value)); fmt_specs.sign = sign::none; fmt_specs.alt = false; - fmt_specs.align = align::right; + // align::numeric needs to be overwritten here since the '0' flag is + // ignored for non-numeric types + if (fmt_specs.align == align::none || fmt_specs.align == align::numeric) + fmt_specs.align = align::right; return base::operator()(value); } else { return base::operator()(value); diff --git a/test/printf-test.cc b/test/printf-test.cc index 5a586797..e556ef36 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -156,6 +156,10 @@ TEST(PrintfTest, PlusFlag) { TEST(PrintfTest, MinusFlag) { EXPECT_PRINTF("abc ", "%-5s", "abc"); EXPECT_PRINTF("abc ", "%0--5s", "abc"); + + EXPECT_PRINTF("7 ", "%-5d", 7); + EXPECT_PRINTF("97 ", "%-5hhi", 'a'); + EXPECT_PRINTF("a ", "%-5c", 'a'); } TEST(PrintfTest, SpaceFlag) {