Skip to content

Commit

Permalink
fix fmt::get for some GCC versions and legacy Clang
Browse files Browse the repository at this point in the history
fixes #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
  • Loading branch information
alexezeder committed Feb 22, 2021
1 parent 2797588 commit 039313b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -3833,18 +3833,28 @@ FMT_CONSTEXPR void advance_to(
auto s = fmt::format("{}", fmt::ptr(p));
\endrst
*/
template <typename T> inline const void* ptr(const T* p) { return p; }
template <typename T> inline const void* ptr(const std::unique_ptr<T>& p) {
template <typename T>
#if FMT_CLANG_VERSION && FMT_CLANG_VERSION < 700
enable_if_t<!std::is_function<T>::value, const void*>
#else
const void*
#endif
ptr(const T* p) {
return p;
}
template <typename T> const void* ptr(const std::unique_ptr<T>& p) {
return p.get();
}
template <typename T> inline const void* ptr(const std::shared_ptr<T>& p) {
template <typename T> const void* ptr(const std::shared_ptr<T>& p) {
return p.get();
}
#if !FMT_MSC_VER
// MSVC lets function pointers decay to void pointers, so this
// overload is unnecessary.
template <typename T, typename... Args>
inline const void* ptr(T (*fn)(Args...)) {
auto ptr(T (*fn)(Args...))
-> enable_if_t<!std::is_convertible<decltype(fn), const void*>(),
const void*> {
return detail::bit_cast<const void*>(fn);
}
#endif
Expand Down

0 comments on commit 039313b

Please sign in to comment.