fix formatter<char*>

This commit is contained in:
timsong-cpp 2023-05-12 19:10:19 -05:00
parent e82bf41a1a
commit 6f0f0d30b2
2 changed files with 17 additions and 1 deletions

View File

@ -2693,7 +2693,7 @@ struct formatter<T, Char,
template <typename Char> \
struct formatter<Type, Char> : formatter<Base, Char> { \
template <typename FormatContext> \
auto format(const Type& val, FormatContext& ctx) const \
auto format(Type const& val, FormatContext& ctx) const \
-> decltype(ctx.out()) { \
return formatter<Base, Char>::format(static_cast<Base>(val), ctx); \
} \

View File

@ -2251,3 +2251,19 @@ TEST(format_test, format_named_arg_with_locale) {
}
#endif // FMT_STATIC_THOUSANDS_SEPARATOR
struct convertible_to_nonconst_cstring {
operator char*() const {
static char c[]="bar";
return c;
}
};
FMT_BEGIN_NAMESPACE
template <> struct formatter<convertible_to_nonconst_cstring> : formatter<char*> {
};
FMT_END_NAMESPACE
TEST(format_test, formatter_nonconst_char) {
EXPECT_EQ(fmt::format("{}", convertible_to_nonconst_cstring()), "bar");
}