Skip to content

Commit 53c5bd7

Browse files
author
Hans-Martin B. Jensen
committed
Fix format_to + FMT_STRING for wide character type
Fixes issue #3802
1 parent aa52eb7 commit 53c5bd7

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Diff for: include/fmt/xchar.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ template <typename OutputIt, typename S, typename... T,
188188
typename Char = detail::format_string_char_t<S>,
189189
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value&&
190190
detail::is_exotic_char<Char>::value)>
191-
inline auto format_to(OutputIt out, const S& fmt, T&&... args) -> OutputIt {
192-
return vformat_to(out, detail::to_string_view(fmt),
191+
inline auto format_to(OutputIt out, const S& format_str, T&&... args) -> OutputIt {
192+
return vformat_to(out, fmt::basic_string_view<Char>(format_str),
193193
fmt::make_format_args<buffered_context<Char>>(args...));
194194
}
195195

@@ -215,7 +215,7 @@ template <typename OutputIt, typename Locale, typename S, typename... T,
215215
inline auto format_to(OutputIt out, const Locale& loc, const S& format_str,
216216
T&&... args) ->
217217
typename std::enable_if<enable, OutputIt>::type {
218-
return vformat_to(out, loc, detail::to_string_view(format_str),
218+
return vformat_to(out, loc, fmt::basic_string_view<Char>(format_str),
219219
fmt::make_format_args<buffered_context<Char>>(args...));
220220
}
221221

Diff for: test/xchar-test.cc

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ TEST(xchar_test, compile_time_string) {
9393
EXPECT_EQ(fmt::format(fmt::wformat_string<int>(L"{}"), 42), L"42");
9494
#if defined(FMT_USE_STRING_VIEW) && FMT_CPLUSPLUS >= 201703L
9595
EXPECT_EQ(fmt::format(FMT_STRING(std::wstring_view(L"{}")), 42), L"42");
96+
std::wstring ws;
97+
fmt::format_to(std::back_inserter(ws), FMT_STRING(L"{}"), 42);
98+
EXPECT_EQ(L"42", ws);
9699
#endif
97100
}
98101

0 commit comments

Comments
 (0)