Detect types convertible to unformattable pointers

This commit is contained in:
Victor Zverovich
2021-11-13 08:26:27 -08:00
parent 094b66e81d
commit 5380ff4d88
2 changed files with 11 additions and 2 deletions

View File

@@ -733,6 +733,10 @@ template <> struct formatter<nonconst_formattable> {
};
FMT_END_NAMESPACE
struct convertible_to_pointer {
operator const int*() const { return nullptr; }
};
TEST(core_test, is_formattable) {
static_assert(fmt::is_formattable<signed char*>::value, "");
static_assert(fmt::is_formattable<unsigned char*>::value, "");
@@ -760,6 +764,8 @@ TEST(core_test, is_formattable) {
static_assert(!fmt::is_formattable<const nonconst_formattable&>::value, "");
#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<unsigned char*, wchar_t>::value, "");
static_assert(!fmt::is_formattable<const signed char*, wchar_t>::value, "");