Pass correct Char to base format_as formatter (#3457)

This commit is contained in:
Nico Rieck 2023-05-24 23:50:47 +02:00 committed by GitHub
parent d8f04e3995
commit 171a020c82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -4104,8 +4104,8 @@ class format_int {
template <typename T, typename Char> template <typename T, typename Char>
struct formatter<T, Char, enable_if_t<detail::has_format_as<T>::value>> struct formatter<T, Char, enable_if_t<detail::has_format_as<T>::value>>
: private formatter<detail::format_as_t<T>> { : private formatter<detail::format_as_t<T>, Char> {
using base = formatter<detail::format_as_t<T>>; using base = formatter<detail::format_as_t<T>, Char>;
using base::parse; using base::parse;
template <typename FormatContext> template <typename FormatContext>

View File

@ -152,6 +152,15 @@ TEST(xchar_test, vformat_to) {
EXPECT_EQ(L"42", w); EXPECT_EQ(L"42", w);
} }
namespace test {
struct struct_as_wstring_view {};
auto format_as(struct_as_wstring_view) -> fmt::wstring_view { return L"foo"; }
} // namespace test
TEST(xchar_test, format_as) {
EXPECT_EQ(fmt::format(L"{}", test::struct_as_wstring_view()), L"foo");
}
TEST(format_test, wide_format_to_n) { TEST(format_test, wide_format_to_n) {
wchar_t buffer[4]; wchar_t buffer[4];
buffer[3] = L'x'; buffer[3] = L'x';