From a3ab36c80399f13e05ff2ff142df58fa9f3fd103 Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Tue, 23 Nov 2021 22:55:22 +0200 Subject: [PATCH] Formatting of function pointers, member function pointers, member object pointers... (#2610) --- include/fmt/core.h | 7 +++++-- test/compile-error-test/CMakeLists.txt | 6 ++++++ test/core-test.cc | 7 +++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index bb56da7f..e2abdece 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1372,8 +1372,11 @@ template struct arg_mapper { // the C array overload. template < typename T, - FMT_ENABLE_IF(std::is_convertible::value && - !std::is_convertible::value)> + FMT_ENABLE_IF( + std::is_member_pointer::value || + std::is_function::type>::value || + (std::is_convertible::value && + !std::is_convertible::value))> FMT_CONSTEXPR auto map(const T&) -> unformattable_pointer { return {}; } diff --git a/test/compile-error-test/CMakeLists.txt b/test/compile-error-test/CMakeLists.txt index 8202f279..44bbb1ab 100644 --- a/test/compile-error-test/CMakeLists.txt +++ b/test/compile-error-test/CMakeLists.txt @@ -67,6 +67,12 @@ expect_compile_error(" fmt::format(\"{}\", S()); ") +# Formatting a function +expect_compile_error(" + void (*f)(); + fmt::format(\"{}\", f); +") + # Make sure that compiler features detected in the header # match the features detected in CMake. if (SUPPORTS_USER_DEFINED_LITERALS) diff --git a/test/core-test.cc b/test/core-test.cc index da3bc0f9..4f39c7ab 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -770,6 +770,13 @@ TEST(core_test, is_formattable) { static_assert(!fmt::is_formattable::value, ""); static_assert(!fmt::is_formattable::value, ""); static_assert(!fmt::is_formattable::value, ""); + + static_assert(!fmt::is_formattable::value, ""); + + struct s; + + static_assert(!fmt::is_formattable::value, ""); + static_assert(!fmt::is_formattable::value, ""); } TEST(core_test, format) { EXPECT_EQ(fmt::format("{}", 42), "42"); }