-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
547e6d1
to
039313b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
include/fmt/format.h
Outdated
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; | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
039313b
to
9e3a2ed
Compare
This is unrelated to this PR, but maybe this overload should also be added later: inline const void* ptr(std::nullptr_t) {
return nullptr;
} |
I don't think it's necessary because |
fix `fmt::get` for some GCC versions and legacy Clang (fmtlib#2144)
Fixes #2140.
Some points:
const T*
pointers but unable to convert themconst void*
, exactly like MSVC doesinline
specifiers removed because all functions are templates