diff --git a/include/fmt/core.h b/include/fmt/core.h index cf294e369d1da..a0e81c48394f8 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -326,8 +326,8 @@ FMT_CONSTEXPR typename std::make_unsigned::type to_unsigned(Int value) { constexpr unsigned char micro[] = "\u00B5"; -constexpr bool is_utf8() { - return FMT_UNICODE || +template constexpr bool is_unicode() { + return FMT_UNICODE || sizeof(Char) != 1 || (sizeof(micro) == 3 && micro[0] == 0xC2 && micro[1] == 0xB5); } @@ -1659,11 +1659,13 @@ typename buffer_context::iterator vformat_to( buffer& buf, basic_string_view format_str, basic_format_args>> args); -FMT_API void vprint_mojibake(std::FILE*, string_view, format_args); +template ::value)> +inline void vprint_mojibake(std::FILE*, + basic_string_view, + basic_format_args) {} -#ifndef _WIN32 -inline void vprint_mojibake(std::FILE*, string_view, format_args) {} -#endif +FMT_API void vprint_mojibake(std::FILE*, string_view, format_args); } // namespace internal /** @@ -1751,10 +1753,9 @@ FMT_API void vprint(std::FILE*, string_view, format_args); fmt::print(stderr, "Don't {}!", "panic"); \endrst */ -template ::value)> +template > inline void print(std::FILE* f, const S& format_str, Args&&... args) { - return internal::is_utf8() + return internal::is_unicode() ? vprint(f, to_string_view(format_str), internal::make_args_checked(format_str, args...)) : internal::vprint_mojibake( @@ -1773,10 +1774,9 @@ inline void print(std::FILE* f, const S& format_str, Args&&... args) { fmt::print("Elapsed time: {0:.2f} seconds", 1.23); \endrst */ -template ::value)> +template > inline void print(const S& format_str, Args&&... args) { - return internal::is_utf8() + return internal::is_unicode() ? vprint(to_string_view(format_str), internal::make_args_checked(format_str, args...)) : internal::vprint_mojibake( diff --git a/test/format-test.cc b/test/format-test.cc index 812c1dcc62954..f7f1360834b42 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1756,6 +1756,7 @@ TEST(FormatTest, Print) { EXPECT_WRITE(stdout, fmt::print("Don't {}!", "panic"), "Don't panic!"); EXPECT_WRITE(stderr, fmt::print(stderr, "Don't {}!", "panic"), "Don't panic!"); + EXPECT_WRITE(stdout, fmt::print(L"test"), "test"); #endif }