-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libc++] Make forward_list constexpr as part of P3372R3 #129435
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
base: main
Are you sure you want to change the base?
Changes from all commits
838c50f
3d213b1
b6fd6de
a5b63dd
7c90175
6b7800a
30daee8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,8 +245,8 @@ inline _LIBCPP_HIDE_FROM_ABI constexpr auto to_address(_Tp* __p) noexcept { | |
} | ||
|
||
template <class _Pointer> | ||
inline _LIBCPP_HIDE_FROM_ABI constexpr auto | ||
to_address(const _Pointer& __p) noexcept -> decltype(std::__to_address(__p)) { | ||
inline _LIBCPP_HIDE_FROM_ABI constexpr auto to_address(const _Pointer& __p) noexcept | ||
-> decltype(std::__to_address(__p)) { | ||
return std::__to_address(__p); | ||
} | ||
#endif | ||
|
@@ -302,6 +302,18 @@ concept __resettable_smart_pointer_with_args = requires(_Smart __s, _Pointer __p | |
|
||
#endif | ||
|
||
// This function ensures safe conversions between fancy pointers at compile-time, where we avoid casts from/to | ||
// `__void_pointer` by obtaining the underlying raw pointer from the fancy pointer using `std::to_address`, | ||
// then dereferencing it to retrieve the pointed-to object, and finally constructing the target fancy pointer | ||
// to that object using the `std::pointer_traits<>::pinter_to` function. | ||
template <class _PtrTo, class _PtrFrom> | ||
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _PtrTo __static_fancy_pointer_cast(const _PtrFrom& __p) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you document what this function does with a short comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason we can't replace the cases like we did in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you referring to #130310 ? If so, that PR (which hasn't landed yet) removes many instances of these casts, but not all of them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess so. I think my main question is whether this utility is still needed after that patch. If not, I think I'd like this patch to be rebased on the other instead of adding a utility we know for a fact is removed by a follow-up patch. That would simplify this patch, which I think is quite important. The "constexpr everything" patches are really difficult to go through due to all the changes (even though none of them are complicated), so every bit of simplification makes it significantly easier to look at. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what #130310 really does is to inline the three cast functions That said, I’d like to land this patch first to guarantee that all fancy pointer-related casts function correctly. Once that’s done, #130310 can rebase and serve as a follow-up to inline the three cast functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't just inline the calls. AFAICT there is no cast to __void_pointer left, which is the part that introduces the problem IIUC. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is that even without the cast to |
||
using __ptr_traits = pointer_traits<_PtrTo>; | ||
using __element_type = typename __ptr_traits::element_type; | ||
return __p ? __ptr_traits::pointer_to(*static_cast<__element_type*>(std::addressof(*__p))) | ||
: static_cast<_PtrTo>(nullptr); | ||
} | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
_LIBCPP_POP_MACROS | ||
|
Uh oh!
There was an error while loading. Please reload this page.