[libcxx-commits] [libcxx] 65d378d - [libc++] Remove `__wrap_iter::base()` (#179389)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 5 04:06:51 PST 2026


Author: William Tran-Viet
Date: 2026-03-05T20:06:46+08:00
New Revision: 65d378d82d127915a5e58dbaaec70315b17d361e

URL: https://github.com/llvm/llvm-project/commit/65d378d82d127915a5e58dbaaec70315b17d361e
DIFF: https://github.com/llvm/llvm-project/commit/65d378d82d127915a5e58dbaaec70315b17d361e.diff

LOG: [libc++] Remove `__wrap_iter::base()` (#179389)

Resolves #126442

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

---------

Co-authored-by: A. Jiang <de34 at live.cn>

Added: 
    

Modified: 
    libcxx/docs/ReleaseNotes/23.rst
    libcxx/include/__iterator/wrap_iter.h
    libcxx/include/regex

Removed: 
    


################################################################################
diff  --git a/libcxx/docs/ReleaseNotes/23.rst b/libcxx/docs/ReleaseNotes/23.rst
index 9519f5b6c2938..7563ca60e75a4 100644
--- a/libcxx/docs/ReleaseNotes/23.rst
+++ b/libcxx/docs/ReleaseNotes/23.rst
@@ -55,6 +55,9 @@ Deprecations and Removals
 - The ``std::launch::any`` enumerator that was accidentally provided as an extension is now deprecated.
   It will be removed in LLVM 25.
 
+- ``__wrap_iter``'s (iterator type for ``array``, ``span``, ``string``, ``string_view`` and ``vector``) ``base()``
+  method has been removed as it was non-standard.
+
 Potentially breaking changes
 ----------------------------
 

diff  --git a/libcxx/include/__iterator/wrap_iter.h b/libcxx/include/__iterator/wrap_iter.h
index 234c9a4f8c704..d20d7f3fc4c4c 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,8 +102,6 @@ class __wrap_iter {
     return __i_[__n];
   }
 
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 iterator_type base() const _NOEXCEPT { return __i_; }
-
 private:
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __wrap_iter(iterator_type __x) _NOEXCEPT : __i_(__x) {}
 
@@ -122,24 +122,24 @@ class __wrap_iter {
 
   _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool
   operator==(const __wrap_iter& __x, const __wrap_iter& __y) _NOEXCEPT {
-    return __x.base() == __y.base();
+    return __x.__i_ == __y.__i_;
   }
 
   template <class _Iter2>
   _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool
   operator==(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
-    return __x.base() == __y.base();
+    return __x.__i_ == __y.__i_;
   }
 
   _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
   operator<(const __wrap_iter& __x, const __wrap_iter& __y) _NOEXCEPT {
-    return __x.base() < __y.base();
+    return __x.__i_ < __y.__i_;
   }
 
   template <class _Iter2>
   _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
   operator<(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
-    return __x.base() < __y.base();
+    return __x.__i_ < __y.__i_;
   }
 
 #if _LIBCPP_STD_VER <= 17
@@ -192,12 +192,12 @@ class __wrap_iter {
   _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering
   operator<=>(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) noexcept {
     if constexpr (three_way_comparable_with<_Iter, _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;
@@ -208,14 +208,14 @@ class __wrap_iter {
 #ifndef _LIBCPP_CXX03_LANG
   template <class _Iter2>
   _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14 auto
-  operator-(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT->decltype(__x.base() - __y.base())
+  operator-(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT->decltype(__x.__i_ - __y.__i_)
 #else
   template <class _Iter2>
   _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14
   typename __wrap_iter::
diff erence_type operator-(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
 #endif // C++03
   {
-    return __x.base() - __y.base();
+    return __x.__i_ - __y.__i_;
   }
 
   _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter
@@ -237,7 +237,7 @@ struct pointer_traits<__wrap_iter<_It> > {
   typedef typename pointer_traits<_It>::
diff erence_type 
diff erence_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..ae6ffcbb55481 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -817,6 +817,7 @@ typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
 #    include <__iterator/wrap_iter.h>
 #    include <__locale>
 #    include <__memory/addressof.h>
+#    include <__memory/pointer_traits.h>
 #    include <__memory/shared_ptr.h>
 #    include <__memory_resource/polymorphic_allocator.h>
 #    include <__type_traits/is_swappable.h>
@@ -5167,7 +5168,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(std::__to_address(__first), std::__to_address(__last), __mc, __flags);
   __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
   return __r;
 }


        


More information about the libcxx-commits mailing list