Skip to content

Commit

Permalink
fix formatter<char*> (#3432)
Browse files Browse the repository at this point in the history
  • Loading branch information
timsong-cpp authored May 20, 2023
1 parent d60b907 commit 08ef0d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2694,7 +2694,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); \
} \
Expand Down
16 changes: 16 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2245,3 +2245,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");
}

0 comments on commit 08ef0d0

Please sign in to comment.