From d671bf524ea25f7f0311bd98e4aaefa10b002a07 Mon Sep 17 00:00:00 2001 From: theomegacarrot Date: Tue, 14 Mar 2023 20:29:17 -0400 Subject: [PATCH] fix case of variant which is valueless by exception --- include/fmt/std.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/include/fmt/std.h b/include/fmt/std.h index 24bf2c53..1583ca21 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -218,11 +218,15 @@ struct formatter< auto out = ctx.out(); out = detail::write(out, "variant("); - std::visit( - [&](const auto& v) { - out = detail::write_variant_alternative(out, v); - }, - value); + try { + std::visit( + [&](const auto& v) { + out = detail::write_variant_alternative(out, v); + }, + value); + } catch (const std::bad_variant_access&) { + detail::write(out, "valueless by exception"); + } *out++ = ')'; return out; }