From 9d13c41ce61329cc85c7c3c67c859ffe2b0e6178 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 11 Jul 2026 08:21:01 -0700 Subject: [PATCH] Format null std::exception_ptr as "none" Change the null exception_ptr representation from "nullptr" to "none" to convey the "no exception" state more clearly, and update the test. --- include/fmt/std.h | 10 +++------- test/std-test.cc | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/fmt/std.h b/include/fmt/std.h index d606508b..207c9d35 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -651,16 +651,12 @@ struct formatter< template <> struct formatter : formatter { template - auto format(const std::exception_ptr& ex_ptr, FormatContext& ctx) const + auto format(const std::exception_ptr& ep, FormatContext& ctx) const -> decltype(ctx.out()) { - if (!ex_ptr) { - return detail::write(ctx.out(), string_view("nullptr")); - } - + if (!ep) return detail::write(ctx.out(), string_view("none")); try { - std::rethrow_exception(ex_ptr); + std::rethrow_exception(ep); } catch (const std::exception& e) { - // Reuses the base formatter::format behavior perfectly return formatter::format(e, ctx); } catch (...) { return detail::write(ctx.out(), string_view("unknown exception")); diff --git a/test/std-test.cc b/test/std-test.cc index b308fe38..d64ef956 100644 --- a/test/std-test.cc +++ b/test/std-test.cc @@ -415,7 +415,7 @@ TEST(std_test, exception_ptr) { p2 = std::current_exception(); } - EXPECT_EQ(fmt::format("{}", p1), "nullptr"); + EXPECT_EQ(fmt::format("{}", p1), "none"); EXPECT_EQ(fmt::format("{}", p2), "My Exception"); #if FMT_USE_RTTI