Skip to content

Commit

Permalink
Use FMT_TRY and FMT_CATCH in std.h (#3482)
Browse files Browse the repository at this point in the history
This naked try-catch block prevents compilation when exceptions are disabled.
  • Loading branch information
Minty-Meeo authored Jun 11, 2023
1 parent 8fe893c commit de0757b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/fmt/std.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <typeinfo>
#include <utility>

#include "format.h"
#include "ostream.h"

#if FMT_HAS_INCLUDE(<version>)
Expand Down Expand Up @@ -234,13 +235,14 @@ struct formatter<
auto out = ctx.out();

out = detail::write<Char>(out, "variant(");
try {
FMT_TRY {
std::visit(
[&](const auto& v) {
out = detail::write_variant_alternative<Char>(out, v);
},
value);
} catch (const std::bad_variant_access&) {
}
FMT_CATCH(const std::bad_variant_access&) {
detail::write<Char>(out, "valueless by exception");
}
*out++ = ')';
Expand Down

0 comments on commit de0757b

Please sign in to comment.