[libcxx-commits] [libcxx] [libc++] Make forward_list constexpr as part of P3372R3 (PR #129435)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 6 01:50:42 PST 2025
================
@@ -295,9 +295,12 @@ struct __forward_node_traits {
"the _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB macro to silence this diagnostic.");
# endif
- _LIBCPP_HIDE_FROM_ABI static __begin_node_pointer __as_iter_node(__begin_node_pointer __p) { return __p; }
- _LIBCPP_HIDE_FROM_ABI static __begin_node_pointer __as_iter_node(__node_pointer __p) {
- return static_cast<__begin_node_pointer>(static_cast<__void_pointer>(__p));
+ _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI static __begin_node_pointer
+ __as_iter_node(__begin_node_pointer __p) {
+ return __p;
+ }
+ _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI static __begin_node_pointer __as_iter_node(__node_pointer __p) {
+ return std::__static_fancy_pointer_cast<__begin_node_pointer>(__p);
----------------
philnik777 wrote:
I'm quite certain this didn't have UB. It's defined behaviour to `reinterpret_cast<Base*>(derived)` if `Base` is the first object after all. Anyways, I think we'd be better off if we don't try to do the round tripping through a `void*` if we can get away with it (which IMO is quite reasonable). That would allow us to collapse the entire `__as_iter_node` construct. Could we do that in a separate patch and rebase this on top to simplify this whole thing?
https://github.com/llvm/llvm-project/pull/129435
More information about the libcxx-commits
mailing list