[libcxx-commits] [libcxx] [libc++] Make forward_list constexpr as part of P3372R3 (PR #129435)

Peng Liu via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 5 07:29:41 PDT 2025


================
@@ -302,6 +302,14 @@ concept __resettable_smart_pointer_with_args = requires(_Smart __s, _Pointer __p
 
 #endif
 
+template <class _PtrTo, class _PtrFrom>
+_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _PtrTo __static_fancy_pointer_cast(const _PtrFrom& __p) {
----------------
winner245 wrote:

I think what #130310 really does is to inline the three cast functions `__as_iter_node`, `__next_as_begin`, `__get_unsafe_node_pointer`, which cast between `__node_pointer` and `__begin_node_pointer` via `__void_pointer`. During runtime evaluation, the intermediate `__void_pointer` is unnecessary. During compile time evaluation, it leads to compilation failure to use `__void_pointer` to cast between fancy pointers (e.g., `min_pointer`), which is why the new utility function `__static_fancy_pointer_cast` was introduced in this patch. `__static_fancy_pointer_cast` works by first extracting the underlying raw pointer from the fancy pointer using `std::to_address`, then dereferencing it to obtain the pointed-to object, and finally acquiring the target fancy pointer to that object. This ensures successful compile-time evaluation pass for fancy pointers. 

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.


https://github.com/llvm/llvm-project/pull/129435


More information about the libcxx-commits mailing list