mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-05 20:41:06 +00:00
Workaround pathological conversion (#2343)
This commit is contained in:
parent
76ee490468
commit
206000a017
@ -1539,7 +1539,7 @@ FMT_CONSTEXPR FMT_INLINE auto make_arg(const T& val) -> value<Context> {
|
||||
!std::is_same<decltype(arg), const unformattable&>::value,
|
||||
"Cannot format an argument. To make type T formattable provide a "
|
||||
"formatter<T> specialization: https://fmt.dev/latest/api.html#udt");
|
||||
return arg;
|
||||
return {arg};
|
||||
}
|
||||
|
||||
template <bool IS_PACKED, typename Context, type, typename T,
|
||||
|
@ -1436,6 +1436,27 @@ TEST(format_test, format_explicitly_convertible_to_std_string_view) {
|
||||
}
|
||||
#endif
|
||||
|
||||
struct converible_to_anything {
|
||||
template <typename T> operator T() const { return T(); }
|
||||
};
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
template <> struct formatter<converible_to_anything> {
|
||||
FMT_CONSTEXPR auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) {
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
auto format(converible_to_anything, format_context& ctx)
|
||||
-> decltype(ctx.out()) {
|
||||
return format_to(ctx.out(), "foo");
|
||||
}
|
||||
};
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
TEST(format_test, format_convertible_to_anything) {
|
||||
EXPECT_EQ("foo", fmt::format("{}", converible_to_anything()));
|
||||
}
|
||||
|
||||
class Answer {};
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
|
Loading…
Reference in New Issue
Block a user