Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parameter type of formatter<char*> #3432

Merged
merged 1 commit into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
} \
Expand Down
16 changes: 16 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}