[libcxx-commits] [libcxx] [libc++][NFC] Remove `pointer_traits<__wrap_iter>` partial specialization (PR #178864)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 5 22:45:09 PST 2026


https://github.com/frederick-vs-ja updated https://github.com/llvm/llvm-project/pull/178864

>From 3374fc0a1bd66cb44d1cfcf9404acc9c1ff4b5c0 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Fri, 30 Jan 2026 18:51:32 +0800
Subject: [PATCH] [libc++][NFC] Remove `pointer_traits<__wrap_iter>` partial
 specialization

It was said that `__wrap_iter` wasn't intended to perform runtime check,
so it's `operator->` won't check whether the iterator is deferenceable.
(See https://llvm.org/PR178521.)

Currently, `pointer_traits<__wrap_iter>` partial specialization is
provided and makes `__to_address`/`to_address` call the member
`to_address` instead of `operator->`. But given these operations are
equivalent and `__wrap_iter::operator->` is improbable to have
behavioral change in the future, perhaps it would be better to remove
the partial specialization.

Also update `pointer_traits<__bounded_iter>` partial specialization to
handle `__bounded_iter<__wrap_iter>`.

Drive-by: Also remove inclusion of `<__memory/addressof.h>` from
`<__iterator/wrap_iter.h>` as we don't need to call `addressof` or its
equivalent internal version.
---
 libcxx/include/__iterator/bounded_iter.h |  5 +++--
 libcxx/include/__iterator/wrap_iter.h    | 12 ------------
 2 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/libcxx/include/__iterator/bounded_iter.h b/libcxx/include/__iterator/bounded_iter.h
index d2a09061126bd..2d4cf6c4aef44 100644
--- a/libcxx/include/__iterator/bounded_iter.h
+++ b/libcxx/include/__iterator/bounded_iter.h
@@ -23,6 +23,7 @@
 #include <__type_traits/is_convertible.h>
 #include <__type_traits/is_same.h>
 #include <__type_traits/make_const_lvalue_ref.h>
+#include <__type_traits/remove_reference.h>
 #include <__utility/move.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -277,8 +278,8 @@ struct __libcpp_is_contiguous_iterator<__bounded_iter<_Iterator> > : true_type {
 template <class _Iterator>
 struct pointer_traits<__bounded_iter<_Iterator> > {
   using pointer         = __bounded_iter<_Iterator>;
-  using element_type    = typename pointer_traits<_Iterator>::element_type;
-  using difference_type = typename pointer_traits<_Iterator>::difference_type;
+  using element_type    = __libcpp_remove_reference_t<typename iterator_traits<_Iterator>::reference>;
+  using difference_type = typename iterator_traits<_Iterator>::difference_type;
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static element_type* to_address(pointer __it) _NOEXCEPT {
     return std::__to_address(__it.__current_);
diff --git a/libcxx/include/__iterator/wrap_iter.h b/libcxx/include/__iterator/wrap_iter.h
index d20d7f3fc4c4c..44727db9fc2cb 100644
--- a/libcxx/include/__iterator/wrap_iter.h
+++ b/libcxx/include/__iterator/wrap_iter.h
@@ -15,7 +15,6 @@
 #include <__config>
 #include <__cstddef/size_t.h>
 #include <__iterator/iterator_traits.h>
-#include <__memory/addressof.h>
 #include <__memory/pointer_traits.h>
 #include <__type_traits/conjunction.h>
 #include <__type_traits/disjunction.h>
@@ -230,17 +229,6 @@ template <class _It>
 struct __libcpp_is_contiguous_iterator<__wrap_iter<_It> > : true_type {};
 #endif
 
-template <class _It>
-struct pointer_traits<__wrap_iter<_It> > {
-  typedef __wrap_iter<_It> pointer;
-  typedef typename pointer_traits<_It>::element_type element_type;
-  typedef typename pointer_traits<_It>::difference_type difference_type;
-
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static element_type* to_address(pointer __w) _NOEXCEPT {
-    return std::__to_address(__w.__i_);
-  }
-};
-
 _LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP___ITERATOR_WRAP_ITER_H



More information about the libcxx-commits mailing list