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 23, 2021
1 parent 2797588 commit 9e3a2ed
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -3833,21 +3833,16 @@ 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) {
return p.get();
template <typename T> const void* ptr(T p) {
static_assert(std::is_pointer<T>::value, "");
return detail::bit_cast<const void*>(p);
}
template <typename T> inline const void* ptr(const std::shared_ptr<T>& p) {
template <typename T> const void* ptr(const std::unique_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...)) {
return detail::bit_cast<const void*>(fn);
template <typename T> const void* ptr(const std::shared_ptr<T>& p) {
return p.get();
}
#endif

class bytes {
private:
Expand Down

0 comments on commit 9e3a2ed

Please sign in to comment.