Skip to content

Commit 08d38d6

Browse files
committed
Make error_code formatter debug-enabled
1 parent a2289b8 commit 08d38d6

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

include/fmt/std.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,8 @@ template <> struct formatter<std::error_code> {
513513
bool debug_ = false;
514514

515515
public:
516+
FMT_CONSTEXPR void set_debug_format(bool set = true) { debug_ = set; }
517+
516518
FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* {
517519
auto it = ctx.begin(), end = ctx.end();
518520
if (it == end) return it;

test/std-test.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <vector>
1414

1515
#include "fmt/os.h" // fmt::system_category
16+
#include "fmt/ranges.h"
1617
#include "gtest-extra.h" // StartsWith
1718

1819
#ifdef __cpp_lib_filesystem
@@ -335,6 +336,10 @@ TEST(std_test, error_code) {
335336
EXPECT_EQ(fmt::format("{:s}", ec), ec.message());
336337
EXPECT_EQ(fmt::format("{:?}", std::error_code(42, generic)),
337338
"\"generic:42\"");
339+
EXPECT_EQ(fmt::format("{}",
340+
std::map<std::error_code, int>{
341+
{std::error_code(42, generic), 0}}),
342+
"{\"generic:42\": 0}");
338343
}
339344

340345
template <typename Catch> void exception_test() {

0 commit comments

Comments
 (0)