diff --git a/include/fmt/std.h b/include/fmt/std.h index ff8b7fd3711a..4095a3873f02 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -64,8 +64,12 @@ FMT_BEGIN_NAMESPACE namespace detail { -template auto get_path_string(const std::filesystem::path& p) { - return p.string(); +template auto get_path_string( + const std::filesystem::path& p, const std::basic_string& native) { + if constexpr (std::is_same_v && std::is_same_v) + return to_utf8(native, to_utf8_error_policy::replace); + else + return p.string(); } template @@ -75,10 +79,6 @@ void write_escaped_path(basic_memory_buffer& quoted, } # ifdef _WIN32 -template <> inline auto get_path_string(const std::filesystem::path& p) { - return to_utf8(p.native(), to_utf8_error_policy::replace); -} - template <> inline void write_escaped_path(memory_buffer& quoted, const std::filesystem::path& p) { @@ -130,7 +130,7 @@ template struct formatter { detail::handle_dynamic_spec(specs.width, width_ref_, ctx); if (!debug_) { - auto s = detail::get_path_string(p); + auto s = detail::get_path_string(p, p.native()); return detail::write(ctx.out(), basic_string_view(s), specs); } auto quoted = basic_memory_buffer();