Author: William Tran-Viet
Date: 2026-02-24T09:18:15+01:00
New Revision: 33025a267d716feac257cb052ef183440d76691b

URL: 
https://github.com/llvm/llvm-project/commit/33025a267d716feac257cb052ef183440d76691b
DIFF: 
https://github.com/llvm/llvm-project/commit/33025a267d716feac257cb052ef183440d76691b.diff

LOG: [libc++] Make `__wrap_iter` comparison operators hidden friends (#179590)

Prelude to #179389

Added: 
    

Modified: 
    libcxx/include/__iterator/wrap_iter.h
    
lldb/test/API/commands/expression/import-std-module/iterator/TestIteratorFromStdModule.py

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__iterator/wrap_iter.h 
b/libcxx/include/__iterator/wrap_iter.h
index 128aeab3ac7cd..234c9a4f8c704 100644
--- a/libcxx/include/__iterator/wrap_iter.h
+++ b/libcxx/include/__iterator/wrap_iter.h
@@ -119,117 +119,111 @@ class __wrap_iter {
   friend struct array;
   template <class _Tp, class>
   friend struct __optional_iterator;
-};
 
-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();
-}
-
-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();
-}
-
-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();
-}
-
-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();
-}
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool
+  operator==(const __wrap_iter& __x, const __wrap_iter& __y) _NOEXCEPT {
+    return __x.base() == __y.base();
+  }
+
+  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();
+  }
+
+  _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();
+  }
+
+  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();
+  }
 
 #if _LIBCPP_STD_VER <= 17
-template <class _Iter1>
-_LIBCPP_HIDE_FROM_ABI
-_LIBCPP_CONSTEXPR bool operator!=(const __wrap_iter<_Iter1>& __x, const 
__wrap_iter<_Iter1>& __y) _NOEXCEPT {
-  return !(__x == __y);
-}
-
-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 == __y);
-}
-template <class _Iter1>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
-operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) 
_NOEXCEPT {
-  return __y < __x;
-}
-
-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 __y < __x;
-}
-
-template <class _Iter1>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
-operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) 
_NOEXCEPT {
-  return !(__x < __y);
-}
-
-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 < __y);
-}
-
-template <class _Iter1>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
-operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) 
_NOEXCEPT {
-  return !(__y < __x);
-}
-
-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 !(__y < __x);
-}
+  _LIBCPP_HIDE_FROM_ABI friend
+      _LIBCPP_CONSTEXPR bool operator!=(const __wrap_iter& __x, const 
__wrap_iter& __y) _NOEXCEPT {
+    return !(__x == __y);
+  }
 
-#else
-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();
-  } else {
-    if (__x.base() < __y.base())
-      return strong_ordering::less;
+  template <class _Iter2>
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool
+  operator!=(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 
{
+    return !(__x == __y);
+  }
 
-    if (__x.base() == __y.base())
-      return strong_ordering::equal;
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool
+  operator>(const __wrap_iter& __x, const __wrap_iter& __y) _NOEXCEPT {
+    return __y < __x;
+  }
+
+  template <class _Iter2>
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool
+  operator>(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
+    return __y < __x;
+  }
 
-    return strong_ordering::greater;
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool
+  operator>=(const __wrap_iter& __x, const __wrap_iter& __y) _NOEXCEPT {
+    return !(__x < __y);
+  }
+
+  template <class _Iter2>
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool
+  operator>=(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 
{
+    return !(__x < __y);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool
+  operator<=(const __wrap_iter& __x, const __wrap_iter& __y) _NOEXCEPT {
+    return !(__y < __x);
+  }
+
+  template <class _Iter2>
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool
+  operator<=(const __wrap_iter& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 
{
+    return !(__y < __x);
+  }
+
+#else
+  template <class _Iter2>
+  _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();
+    } else {
+      if (__x.base() < __y.base())
+        return strong_ordering::less;
+
+      if (__x.base() == __y.base())
+        return strong_ordering::equal;
+
+      return strong_ordering::greater;
+    }
   }
-}
 #endif // _LIBCPP_STD_VER >= 20
 
-template <class _Iter1, class _Iter2>
-_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())
+  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())
 #else
-typename __wrap_iter<_Iter1>::
diff erence_type
-operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) 
_NOEXCEPT
+  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();
-}
-
-template <class _Iter1>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter<_Iter1>
-operator+(typename __wrap_iter<_Iter1>::
diff erence_type __n, __wrap_iter<_Iter1> __x) _NOEXCEPT {
-  __x += __n;
-  return __x;
-}
+  {
+    return __x.base() - __y.base();
+  }
+
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter
+  operator+(typename __wrap_iter::
diff erence_type __n, __wrap_iter __x) _NOEXCEPT {
+    __x += __n;
+    return __x;
+  }
+};
 
 #if _LIBCPP_STD_VER <= 17
 template <class _It>

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/iterator/TestIteratorFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/iterator/TestIteratorFromStdModule.py
index 370c3674faeca..f0b3b5445cf63 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/iterator/TestIteratorFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/iterator/TestIteratorFromStdModule.py
@@ -27,6 +27,18 @@ def test(self):
 
         self.expect_expr("move_begin + 3 == move_end", result_value="true")
 
+    @add_test_categories(["libc++"])
+    @skipIf(compiler=no_match("clang"))
+    
@expectedFailureAll(bugnumber="https://github.com/llvm/llvm-project/issues/149477";)
+    def test_xfail(self):
+        self.build()
+
+        lldbutil.run_to_source_breakpoint(
+            self, "// Set break point at this line.", 
lldb.SBFileSpec("main.cpp")
+        )
+
+        self.runCmd("settings set target.import-std-module true")
+
         self.expect("expr move_begin++")
         self.expect_expr("move_begin + 2 == move_end", result_value="true")
         self.expect("expr move_begin--")


        
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to