From 80e332f4d64f0205579cfe4c60d724054fb74126 Mon Sep 17 00:00:00 2001 From: TheRodzz <81969589+TheRodzz@users.noreply.github.com> Date: Tue, 25 Aug 2026 03:44:24 +0000 Subject: [PATCH] Fix default alignment for inf/nan --- include/fmt/format.h | 11 +++++------ test/format-test.cc | 2 ++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index d74c3e93c14d..4697d3c7636f 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2402,12 +2402,11 @@ FMT_CONSTEXPR20 auto write_nonfinite(OutputIt out, bool isnan, const bool is_zero_fill = specs.fill_size() == 1 && specs.fill_unit() == '0'; if (is_zero_fill) specs.set_fill(' '); - return write_padded(out, specs, size, - [=](reserve_iterator it) { - if (s != sign::none) - *it++ = detail::getsign(s); - return copy(str, str + str_size, it); - }); + return write_padded( + out, specs, size, [=](reserve_iterator it) { + if (s != sign::none) *it++ = detail::getsign(s); + return copy(str, str + str_size, it); + }); } // A decimal floating-point number significand * pow(10, exp). diff --git a/test/format-test.cc b/test/format-test.cc index c16de4b2794d..ea65f0a3cec8 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1622,6 +1622,7 @@ TEST(format_test, format_nan) { EXPECT_EQ(fmt::format("{:<7}", nan), "nan "); EXPECT_EQ(fmt::format("{:^7}", nan), " nan "); EXPECT_EQ(fmt::format("{:>7}", nan), " nan"); + EXPECT_EQ(fmt::format("{:7}", nan), " nan"); } TEST(format_test, format_infinity) { @@ -1639,6 +1640,7 @@ TEST(format_test, format_infinity) { EXPECT_EQ(fmt::format("{:<7}", inf), "inf "); EXPECT_EQ(fmt::format("{:^7}", inf), " inf "); EXPECT_EQ(fmt::format("{:>7}", inf), " inf"); + EXPECT_EQ(fmt::format("{:7}", inf), " inf"); } TEST(format_test, format_long_double) {