diff --git a/include/fmt/format.h b/include/fmt/format.h index d635b91d..dc2336cd 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2787,7 +2787,8 @@ void basic_writer::write_double(T value, const format_specs &spec) { if (sign) { *reserve(1) = sign; sign = 0; - --as.width_; + if (as.width_) + --as.width_; } as.align_ = ALIGN_RIGHT; } else { diff --git a/test/format-test.cc b/test/format-test.cc index 62bf224e..17dedd3b 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -532,6 +532,7 @@ TEST(FormatterTest, NumericAlign) { 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", fmt::format("{:= }", 1.0)); } TEST(FormatterTest, CenterAlign) {