mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-25 03:30:05 +00:00
Disable remaining implicit conversions
This commit is contained in:
parent
9ce6480676
commit
9e4a54fa6e
@ -1438,25 +1438,6 @@ template <typename Context> struct arg_mapper {
|
||||
FMT_CONSTEXPR FMT_INLINE auto map(const T&) -> unformattable_char {
|
||||
return {};
|
||||
}
|
||||
template <typename T,
|
||||
FMT_ENABLE_IF(
|
||||
std::is_convertible<T, basic_string_view<char_type>>::value &&
|
||||
!is_string<T>::value && !has_formatter<T, Context>::value &&
|
||||
!has_fallback_formatter<T, char_type>::value)>
|
||||
FMT_CONSTEXPR FMT_INLINE auto map(const T& val)
|
||||
-> basic_string_view<char_type> {
|
||||
return basic_string_view<char_type>(val);
|
||||
}
|
||||
template <typename T,
|
||||
FMT_ENABLE_IF(
|
||||
std::is_convertible<T, std_string_view<char_type>>::value &&
|
||||
!std::is_convertible<T, basic_string_view<char_type>>::value &&
|
||||
!is_string<T>::value && !has_formatter<T, Context>::value &&
|
||||
!has_fallback_formatter<T, char_type>::value)>
|
||||
FMT_CONSTEXPR FMT_INLINE auto map(const T& val)
|
||||
-> basic_string_view<char_type> {
|
||||
return std_string_view<char_type>(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 <typename Context> 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(
|
||||
|
@ -167,10 +167,10 @@ void detail::format_windows_error(detail::buffer<char>& 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<char>(out), "{}: {}", message,
|
||||
utf8_message);
|
||||
string_view(utf8_message));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -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<implicitly_convertible_to_string_view>::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<implicitly_convertible_to_std_string_view>::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 {
|
||||
|
@ -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) {
|
||||
|
@ -168,19 +168,6 @@ TEST(ranges_test, path_like) {
|
||||
EXPECT_FALSE((fmt::is_range<path_like, char>::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<convertible_to_string_view>(1)),
|
||||
"[\"foo\"]");
|
||||
}
|
||||
#endif // FMT_USE_STRING_VIEW
|
||||
|
||||
template <typename R> struct fmt_ref_view {
|
||||
R* r;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user