From 08d38d6e78e370768ebb7c0fb6b547a2db71d92c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 19 Oct 2025 10:35:45 -0700 Subject: [PATCH] Make error_code formatter debug-enabled --- include/fmt/std.h | 2 ++ test/std-test.cc | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/include/fmt/std.h b/include/fmt/std.h index 3fe795bf..bfa13fa0 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -513,6 +513,8 @@ template <> struct formatter { bool debug_ = false; public: + FMT_CONSTEXPR void set_debug_format(bool set = true) { debug_ = set; } + FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* { auto it = ctx.begin(), end = ctx.end(); if (it == end) return it; diff --git a/test/std-test.cc b/test/std-test.cc index 3fdf0532..18f6bd3f 100644 --- a/test/std-test.cc +++ b/test/std-test.cc @@ -13,6 +13,7 @@ #include #include "fmt/os.h" // fmt::system_category +#include "fmt/ranges.h" #include "gtest-extra.h" // StartsWith #ifdef __cpp_lib_filesystem @@ -335,6 +336,10 @@ TEST(std_test, error_code) { EXPECT_EQ(fmt::format("{:s}", ec), ec.message()); EXPECT_EQ(fmt::format("{:?}", std::error_code(42, generic)), "\"generic:42\""); + EXPECT_EQ(fmt::format("{}", + std::map{ + {std::error_code(42, generic), 0}}), + "{\"generic:42\": 0}"); } template void exception_test() {