From d8e1c9f175a363e7cfe8ff340df2f77d682bc344 Mon Sep 17 00:00:00 2001 From: Alexey Ochapov Date: Tue, 23 Feb 2021 18:18:30 +0300 Subject: [PATCH] fix `fmt::get` for some GCC versions and legacy Clang (#2144) fixes https://github.com/fmtlib/fmt/issues/2140 - some GCC versions decay function pointers to `const void*`, exactly like MSVC does - legacy Clang (prior to 7.0) treats function pointers also as `const T*` pointers, but unable to convert them --- include/fmt/format.h | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 53094c1a..6d5c1f69 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3833,21 +3833,16 @@ FMT_CONSTEXPR void advance_to( auto s = fmt::format("{}", fmt::ptr(p)); \endrst */ -template inline const void* ptr(const T* p) { return p; } -template inline const void* ptr(const std::unique_ptr& p) { +template const void* ptr(T p) { + static_assert(std::is_pointer::value, ""); + return detail::bit_cast(p); +} +template const void* ptr(const std::unique_ptr& p) { return p.get(); } -template inline const void* ptr(const std::shared_ptr& p) { +template const void* ptr(const std::shared_ptr& p) { return p.get(); } -#if !FMT_MSC_VER -// MSVC lets function pointers decay to void pointers, so this -// overload is unnecessary. -template -inline const void* ptr(T (*fn)(Args...)) { - return detail::bit_cast(fn); -} -#endif class bytes { private: