Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fmt::get with function pointers for some GCC versions and legacy Clang #2144

Merged
merged 1 commit into from
Feb 23, 2021

Conversation

alexezeder
Copy link
Contributor

Fixes #2140.

Some points:

  • legacy Clang (prior to 7.0) treats function pointers also as const T* pointers but unable to convert them
  • some GCC versions decay function pointers to const void*, exactly like MSVC does
  • inline specifiers removed because all functions are templates

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment on lines 3836 to 3839
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to

template <typename T>
const void* ptr(T p) {
  static_assert(std::is_pointer<T>::value, "");
  return detail::bit_cast<const void*>(p);
}

and remove the ptr(T (*fn)(Args...)) overload below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can. Another great code simplification.

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
@alexezeder
Copy link
Contributor Author

This is unrelated to this PR, but maybe this overload should also be added later:

inline const void* ptr(std::nullptr_t) {
  return nullptr;
}

@alexezeder alexezeder requested a review from vitaut February 23, 2021 07:13
@vitaut vitaut merged commit d8e1c9f into fmtlib:master Feb 23, 2021
@vitaut
Copy link
Contributor

vitaut commented Feb 23, 2021

This is unrelated to this PR, but maybe this overload should also be added later

I don't think it's necessary because nullptr can be passed directly. ptr is there for typed pointers.

sthagen added a commit to sthagen/fmtlib-fmt that referenced this pull request Feb 23, 2021
fix `fmt::get` for some GCC versions and legacy Clang (fmtlib#2144)
@alexezeder alexezeder deleted the fix/issue-2140 branch March 8, 2021 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make error
2 participants