Skip to content

Commit

Permalink
Fix format_to + FMT_STRING for wide character type
Browse files Browse the repository at this point in the history
Fixes issue fmtlib#3802
  • Loading branch information
hmbj committed Apr 14, 2024
1 parent aa52eb7 commit 53c5bd7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/fmt/xchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ template <typename OutputIt, typename S, typename... T,
typename Char = detail::format_string_char_t<S>,
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value&&
detail::is_exotic_char<Char>::value)>
inline auto format_to(OutputIt out, const S& fmt, T&&... args) -> OutputIt {
return vformat_to(out, detail::to_string_view(fmt),
inline auto format_to(OutputIt out, const S& format_str, T&&... args) -> OutputIt {
return vformat_to(out, fmt::basic_string_view<Char>(format_str),
fmt::make_format_args<buffered_context<Char>>(args...));
}

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

Expand Down
3 changes: 3 additions & 0 deletions test/xchar-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ TEST(xchar_test, compile_time_string) {
EXPECT_EQ(fmt::format(fmt::wformat_string<int>(L"{}"), 42), L"42");
#if defined(FMT_USE_STRING_VIEW) && FMT_CPLUSPLUS >= 201703L
EXPECT_EQ(fmt::format(FMT_STRING(std::wstring_view(L"{}")), 42), L"42");
std::wstring ws;
fmt::format_to(std::back_inserter(ws), FMT_STRING(L"{}"), 42);
EXPECT_EQ(L"42", ws);
#endif
}

Expand Down

0 comments on commit 53c5bd7

Please sign in to comment.