diff --git a/include/fmt/core.h b/include/fmt/core.h index cf294e369d1da..ad8194c6d1fa5 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,8 +1659,11 @@ 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, const Args&) {} +FMT_API void vprint_mojibake(std::FILE*, string_view, format_args); #ifndef _WIN32 inline void vprint_mojibake(std::FILE*, string_view, format_args) {} #endif @@ -1751,10 +1754,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 +1775,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..12e3213914728 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1757,6 +1757,8 @@ TEST(FormatTest, Print) { EXPECT_WRITE(stderr, fmt::print(stderr, "Don't {}!", "panic"), "Don't panic!"); #endif + // Check that the wide print overload compiles. + if (fmt::internal::const_check(false)) fmt::print(L"test"); } TEST(FormatTest, Variadic) {