[libcxx-commits] [libcxx] [libc++] Remove identity casts in <{forward_, }list> (PR #130049)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 6 02:09:39 PST 2025


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/130049

None

>From 095e1af0edb9e185d7b31438e95701e80d923ca8 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Thu, 6 Mar 2025 11:09:20 +0100
Subject: [PATCH] [libc++] Remove identity casts in <{forward_,}list>

---
 libcxx/include/forward_list | 7 ++-----
 libcxx/include/list         | 8 +-------
 2 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list
index 8c688611d5ee2..7582de20995b9 100644
--- a/libcxx/include/forward_list
+++ b/libcxx/include/forward_list
@@ -295,7 +295,6 @@ 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));
   }
@@ -373,8 +372,7 @@ class _LIBCPP_TEMPLATE_VIS __forward_list_iterator {
 
   _LIBCPP_HIDE_FROM_ABI explicit __forward_list_iterator(nullptr_t) _NOEXCEPT : __ptr_(nullptr) {}
 
-  _LIBCPP_HIDE_FROM_ABI explicit __forward_list_iterator(__begin_node_pointer __p) _NOEXCEPT
-      : __ptr_(__traits::__as_iter_node(__p)) {}
+  _LIBCPP_HIDE_FROM_ABI explicit __forward_list_iterator(__begin_node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
 
   _LIBCPP_HIDE_FROM_ABI explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT
       : __ptr_(__traits::__as_iter_node(__p)) {}
@@ -438,8 +436,7 @@ class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator {
 
   _LIBCPP_HIDE_FROM_ABI explicit __forward_list_const_iterator(nullptr_t) _NOEXCEPT : __ptr_(nullptr) {}
 
-  _LIBCPP_HIDE_FROM_ABI explicit __forward_list_const_iterator(__begin_node_pointer __p) _NOEXCEPT
-      : __ptr_(__traits::__as_iter_node(__p)) {}
+  _LIBCPP_HIDE_FROM_ABI explicit __forward_list_const_iterator(__begin_node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
 
   _LIBCPP_HIDE_FROM_ABI explicit __forward_list_const_iterator(__node_pointer __p) _NOEXCEPT
       : __ptr_(__traits::__as_iter_node(__p)) {}
diff --git a/libcxx/include/list b/libcxx/include/list
index 1285174f1c384..5d5304cced872 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -286,12 +286,6 @@ struct __list_node_pointer_traits {
                 "LLVM 19 and LLVM 20. If you don't care about your ABI being broken, define the "
                 "_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB macro to silence this diagnostic.");
 #  endif
-
-  static _LIBCPP_HIDE_FROM_ABI __base_pointer __unsafe_link_pointer_cast(__base_pointer __p) { return __p; }
-
-  static _LIBCPP_HIDE_FROM_ABI __base_pointer __unsafe_link_pointer_cast(__node_pointer __p) {
-    return static_cast<__base_pointer>(static_cast<_VoidPtr>(__p));
-  }
 };
 
 template <class _Tp, class _VoidPtr>
@@ -504,7 +498,7 @@ protected:
   _LIBCPP_COMPRESSED_PAIR(size_type, __size_, __node_allocator, __node_alloc_);
 
   _LIBCPP_HIDE_FROM_ABI __base_pointer __end_as_link() const _NOEXCEPT {
-    return __node_pointer_traits::__unsafe_link_pointer_cast(const_cast<__node_base&>(__end_).__self());
+    return const_cast<__node_base&>(__end_).__self();
   }
 
   _LIBCPP_HIDE_FROM_ABI size_type __node_alloc_max_size() const _NOEXCEPT {



More information about the libcxx-commits mailing list