diff --git a/include/fmt/core.h b/include/fmt/core.h index 0e3822e9..9e4fe9cc 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1438,25 +1438,6 @@ template struct arg_mapper { FMT_CONSTEXPR FMT_INLINE auto map(const T&) -> unformattable_char { return {}; } - template >::value && - !is_string::value && !has_formatter::value && - !has_fallback_formatter::value)> - FMT_CONSTEXPR FMT_INLINE auto map(const T& val) - -> basic_string_view { - return basic_string_view(val); - } - template >::value && - !std::is_convertible>::value && - !is_string::value && !has_formatter::value && - !has_fallback_formatter::value)> - FMT_CONSTEXPR FMT_INLINE auto map(const T& val) - -> basic_string_view { - return std_string_view(val); - } FMT_CONSTEXPR FMT_INLINE auto map(void* val) -> const void* { return val; } FMT_CONSTEXPR FMT_INLINE auto map(const void* val) -> const void* { @@ -1466,8 +1447,8 @@ template struct arg_mapper { return val; } - // We use SFINAE instead of a const T* parameter to avoid conflicting with - // the C array overload. + // Use SFINAE instead of a const T* parameter to avoid a conflict with the + // array overload. template < typename T, FMT_ENABLE_IF( diff --git a/src/os.cc b/src/os.cc index 999d2a75..75befaf5 100644 --- a/src/os.cc +++ b/src/os.cc @@ -167,10 +167,10 @@ void detail::format_windows_error(detail::buffer& out, int error_code, FMT_TRY { system_message msg(error_code); if (msg) { - utf16_to_utf8 utf8_message; + auto utf8_message = utf16_to_utf8(); if (utf8_message.convert(msg) == ERROR_SUCCESS) { fmt::format_to(buffer_appender(out), "{}: {}", message, - utf8_message); + string_view(utf8_message)); return; } } diff --git a/test/core-test.cc b/test/core-test.cc index 15d69bcc..e57c92b3 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -800,18 +800,26 @@ TEST(core_test, to_string_view_foreign_strings) { EXPECT_EQ(type, fmt::detail::type::string_type); } -struct implicitly_convertible_to_string { - operator std::string() const { return "foo"; } -}; - struct implicitly_convertible_to_string_view { operator fmt::string_view() const { return "foo"; } }; -TEST(core_test, format_implicitly_convertible_to_string_view) { - EXPECT_EQ("foo", fmt::format("{}", implicitly_convertible_to_string_view())); +TEST(core_test, no_implicit_conversion_to_string_view) { + EXPECT_FALSE( + fmt::is_formattable::value); } +#ifdef FMT_USE_STRING_VIEW +struct implicitly_convertible_to_std_string_view { + operator std::string_view() const { return "foo"; } +}; + +TEST(core_test, no_implicit_conversion_to_std_string_view) { + EXPECT_FALSE( + fmt::is_formattable::value); +} +#endif + // std::is_constructible is broken in MSVC until version 2015. #if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1900 struct explicitly_convertible_to_string_view { diff --git a/test/ostream-test.cc b/test/ostream-test.cc index 24c85890..4ba1279f 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -242,21 +242,6 @@ TEST(ostream_test, format_convertible_to_bool) { EXPECT_EQ(fmt::format("{}", streamable_and_convertible_to_bool()), "true"); } -struct streamable_and_convertible_to_string_view { - operator fmt::string_view() const { return "foo"; } -}; - -std::ostream& operator<<(std::ostream& os, - streamable_and_convertible_to_string_view) { - return os << "bar"; -} - -TEST(ostream_test, format_convertible_to_string_vew) { - // operator<< is intentionally not used because of potential ODR violations. - EXPECT_EQ(fmt::format("{}", streamable_and_convertible_to_string_view()), - "foo"); -} - struct copyfmt_test {}; std::ostream& operator<<(std::ostream& os, copyfmt_test) { diff --git a/test/ranges-test.cc b/test/ranges-test.cc index 650b0e85..fa46fc41 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -168,19 +168,6 @@ TEST(ranges_test, path_like) { EXPECT_FALSE((fmt::is_range::value)); } -#ifdef FMT_USE_STRING_VIEW -struct string_like { - const char* begin(); - const char* end(); - operator fmt::string_view() const { return "foo"; } - operator std::string_view() const { return "foo"; } -}; - -TEST(ranges_test, format_string_like) { - EXPECT_EQ(fmt::format("{}", string_like()), "foo"); -} -#endif // FMT_USE_STRING_VIEW - // A range that provides non-const only begin()/end() to test fmt::join handles // that. // @@ -401,17 +388,6 @@ TEST(ranges_test, escape_string) { } } -#ifdef FMT_USE_STRING_VIEW -struct convertible_to_string_view { - operator std::string_view() const { return "foo"; } -}; - -TEST(ranges_test, escape_convertible_to_string_view) { - EXPECT_EQ(fmt::format("{}", std::vector(1)), - "[\"foo\"]"); -} -#endif // FMT_USE_STRING_VIEW - template struct fmt_ref_view { R* r;