Commit 5380ff4d authored by Victor Zverovich's avatar Victor Zverovich

Detect types convertible to unformattable pointers

parent 094b66e8
...@@ -1370,8 +1370,11 @@ template <typename Context> struct arg_mapper { ...@@ -1370,8 +1370,11 @@ template <typename Context> struct arg_mapper {
// We use SFINAE instead of a const T* parameter to avoid conflicting with // We use SFINAE instead of a const T* parameter to avoid conflicting with
// the C array overload. // the C array overload.
template <typename T, FMT_ENABLE_IF(std::is_pointer<T>::value)> template <
FMT_CONSTEXPR auto map(T) -> unformattable_pointer { typename T,
FMT_ENABLE_IF(std::is_convertible<const T&, const void*>::value &&
!std::is_convertible<const T&, const char_type*>::value)>
FMT_CONSTEXPR auto map(const T&) -> unformattable_pointer {
return {}; return {};
} }
......
...@@ -733,6 +733,10 @@ template <> struct formatter<nonconst_formattable> { ...@@ -733,6 +733,10 @@ template <> struct formatter<nonconst_formattable> {
}; };
FMT_END_NAMESPACE FMT_END_NAMESPACE
struct convertible_to_pointer {
operator const int*() const { return nullptr; }
};
TEST(core_test, is_formattable) { TEST(core_test, is_formattable) {
static_assert(fmt::is_formattable<signed char*>::value, ""); static_assert(fmt::is_formattable<signed char*>::value, "");
static_assert(fmt::is_formattable<unsigned char*>::value, ""); static_assert(fmt::is_formattable<unsigned char*>::value, "");
...@@ -760,6 +764,8 @@ TEST(core_test, is_formattable) { ...@@ -760,6 +764,8 @@ TEST(core_test, is_formattable) {
static_assert(!fmt::is_formattable<const nonconst_formattable&>::value, ""); static_assert(!fmt::is_formattable<const nonconst_formattable&>::value, "");
#endif #endif
static_assert(!fmt::is_formattable<convertible_to_pointer>::value, "");
static_assert(!fmt::is_formattable<signed char*, wchar_t>::value, ""); static_assert(!fmt::is_formattable<signed char*, wchar_t>::value, "");
static_assert(!fmt::is_formattable<unsigned char*, wchar_t>::value, ""); static_assert(!fmt::is_formattable<unsigned char*, wchar_t>::value, "");
static_assert(!fmt::is_formattable<const signed char*, wchar_t>::value, ""); static_assert(!fmt::is_formattable<const signed char*, wchar_t>::value, "");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment