[libcxx-commits] [libcxx] [libc++] Remove `wrap_iter::base()` (PR #179389)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Feb 2 20:07:23 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: William Tran-Viet (smallp-o-p)

<details>
<summary>Changes</summary>

Resolves #<!-- -->126442

- Converts all the relevant functions that used `.base()` into friends
- Fixed usage in `<regex>`

---
Full diff: https://github.com/llvm/llvm-project/pull/179389.diff


3 Files Affected:

- (modified) libcxx/docs/ReleaseNotes/22.rst (+3) 
- (modified) libcxx/include/__iterator/wrap_iter.h (+44-12) 
- (modified) libcxx/include/regex (+1-1) 


``````````diff
diff --git a/libcxx/docs/ReleaseNotes/22.rst b/libcxx/docs/ReleaseNotes/22.rst
index 4d56c82a53170..b3727c6210baa 100644
--- a/libcxx/docs/ReleaseNotes/22.rst
+++ b/libcxx/docs/ReleaseNotes/22.rst
@@ -120,6 +120,9 @@ Potentially breaking changes
   ``_LIBCPP_ABI_NO_ITERATOR_BASES``. If you are using this flag and care about ABI stability, you should set
   ``_LIBCPP_ABI_NO_REVERSE_ITERATOR_SECOND_MEMBER`` as well.
 
+- The `base()` function exposed by the contiguous iterator type `wrap_iter` has been removed. Code should no longer
+  rely on this function.
+
 Announcements About Future Releases
 -----------------------------------
 
diff --git a/libcxx/include/__iterator/wrap_iter.h b/libcxx/include/__iterator/wrap_iter.h
index 98745f600a6ec..769d6d73c105f 100644
--- a/libcxx/include/__iterator/wrap_iter.h
+++ b/libcxx/include/__iterator/wrap_iter.h
@@ -47,6 +47,8 @@ class __wrap_iter {
 private:
   iterator_type __i_;
 
+  friend struct pointer_traits<__wrap_iter<_Iter>>;
+
 public:
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter() _NOEXCEPT : __i_() {}
   template <class _OtherIter,
@@ -100,9 +102,39 @@ class __wrap_iter {
     return __i_[__n];
   }
 
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 iterator_type base() const _NOEXCEPT { return __i_; }
-
 private:
+  template <class _Iter1>
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool
+  operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT;
+
+  template <class _Iter1, class _Iter2>
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool
+  operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT;
+
+  template <class _Iter1>
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
+  operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT;
+
+  template <class _Iter1, class _Iter2>
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
+  operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT;
+
+#if _LIBCPP_STD_VER >= 20
+  template <class _Iter1, class _Iter2>
+  _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering
+  operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept;
+#endif
+
+  template <class _Iter1, class _Iter2>
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14
+#ifndef _LIBCPP_CXX03_LANG
+  auto
+  operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT->decltype(__x.__i_ - __y.__i_);
+#else
+  typename __wrap_iter<_Iter>::difference_type
+  operator-(const __wrap_iter<_Iter>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT;
+#endif // C++03
+
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __wrap_iter(iterator_type __x) _NOEXCEPT : __i_(__x) {}
 
   template <class _Up>
@@ -124,25 +156,25 @@ class __wrap_iter {
 template <class _Iter1>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
 operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
-  return __x.base() == __y.base();
+  return __x.__i_ == __y.__i_;
 }
 
 template <class _Iter1, class _Iter2>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
 operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
-  return __x.base() == __y.base();
+  return __x.__i_ == __y.__i_;
 }
 
 template <class _Iter1>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
 operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
-  return __x.base() < __y.base();
+  return __x.__i_ < __y.__i_;
 }
 
 template <class _Iter1, class _Iter2>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
 operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
-  return __x.base() < __y.base();
+  return __x.__i_ < __y.__i_;
 }
 
 #if _LIBCPP_STD_VER <= 17
@@ -198,12 +230,12 @@ template <class _Iter1, class _Iter2>
 _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
 operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept {
   if constexpr (three_way_comparable_with<_Iter1, _Iter2, strong_ordering>) {
-    return __x.base() <=> __y.base();
+    return __x.__i_ <=> __y.__i_;
   } else {
-    if (__x.base() < __y.base())
+    if (__x.__i_ < __y.__i_)
       return strong_ordering::less;
 
-    if (__x.base() == __y.base())
+    if (__x.__i_ == __y.__i_)
       return strong_ordering::equal;
 
     return strong_ordering::greater;
@@ -216,13 +248,13 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
 #ifndef _LIBCPP_CXX03_LANG
     auto
     operator-(const __wrap_iter<_Iter1>& __x,
-              const __wrap_iter<_Iter2>& __y) _NOEXCEPT->decltype(__x.base() - __y.base())
+              const __wrap_iter<_Iter2>& __y) _NOEXCEPT->decltype(__x.__i_ - __y.__i_)
 #else
 typename __wrap_iter<_Iter1>::difference_type
 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
 #endif // C++03
 {
-  return __x.base() - __y.base();
+  return __x.__i_ - __y.__i_;
 }
 
 template <class _Iter1>
@@ -244,7 +276,7 @@ struct pointer_traits<__wrap_iter<_It> > {
   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.base());
+    return std::__to_address(__w.__i_);
   }
 };
 
diff --git a/libcxx/include/regex b/libcxx/include/regex
index 620a75f35d102..c17ecdb3494c2 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -5167,7 +5167,7 @@ regex_search(__wrap_iter<_Iter> __first,
              const basic_regex<_CharT, _Traits>& __e,
              regex_constants::match_flag_type __flags = regex_constants::match_default) {
   match_results<const _CharT*> __mc;
-  bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags);
+  bool __r = __e.__search(__first.operator->(), __last.operator->(), __mc, __flags);
   __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
   return __r;
 }

``````````

</details>


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


More information about the libcxx-commits mailing list