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 fmtlib#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 547e6d1
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -3833,21 +3833,27 @@ 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

class bytes {
private:
Expand Down

0 comments on commit 547e6d1

Please sign in to comment.