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

Peng Liu via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 11 07:08:49 PDT 2025


================
@@ -297,14 +297,20 @@ struct __list_node_base {
   __base_pointer __prev_;
   __base_pointer __next_;
 
-  _LIBCPP_HIDE_FROM_ABI __list_node_base() : __prev_(__self()), __next_(__self()) {}
+  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_node_base() : __prev_(__self()), __next_(__self()) {}
 
+  _LIBCPP_CONSTEXPR_SINCE_CXX26
   _LIBCPP_HIDE_FROM_ABI explicit __list_node_base(__base_pointer __prev, __base_pointer __next)
       : __prev_(__prev), __next_(__next) {}
 
-  _LIBCPP_HIDE_FROM_ABI __base_pointer __self() { return pointer_traits<__base_pointer>::pointer_to(*this); }
+  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __base_pointer __self() {
+    return pointer_traits<__base_pointer>::pointer_to(*this);
+  }
 
-  _LIBCPP_HIDE_FROM_ABI __node_pointer __as_node() { return static_cast<__node_pointer>(__self()); }
+  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __node_pointer __as_node() {
+    return pointer_traits<__node_pointer>::pointer_to(
+        *static_cast<typename pointer_traits<__node_pointer>::element_type*>(this));
----------------
winner245 wrote:

Yes, you are right. The `this` pointer is guaranteed to be non-null (in general, we need to deal with the `nullptr` case). 

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


More information about the libcxx-commits mailing list