[libcxx-commits] [libcxx] [libcxx] applies integer-like changes from [P2393R1] (PR #74161)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 21 01:25:07 PDT 2026


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

>From 48f58fcbd559519e88d14cd8def3bc1331468b04 Mon Sep 17 00:00:00 2001
From: Christopher Di Bella <cjdb at google.com>
Date: Fri, 1 Dec 2023 23:30:06 +0000
Subject: [PATCH 1/6] [libcxx] applies integer-like changes from [P2393R1]

libc++ is already conforming with this paper since its _integer-like_
types are extended integral types. Given that Clang supports `_BitInt`
as a C++ extension, there isn't a need to support class-types' potential
explicit conversion requriements.

We still do so, however, because software development is malleable.
These changes don't impact codegen or correctness, and this will add
resilience to change if the above paragraph ultimately proves false.

[P2393R1]: http://wg21.link/p2393r1
---
 libcxx/docs/Status/Cxx23Papers.csv  |  2 +-
 libcxx/include/__ranges/counted.h   | 13 +++++++------
 libcxx/include/__ranges/subrange.h  | 13 +++++--------
 libcxx/include/__ranges/take_view.h |  8 ++++----
 4 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/libcxx/docs/Status/Cxx23Papers.csv b/libcxx/docs/Status/Cxx23Papers.csv
index b4f915d37d002..c72d64e4220d0 100644
--- a/libcxx/docs/Status/Cxx23Papers.csv
+++ b/libcxx/docs/Status/Cxx23Papers.csv
@@ -35,7 +35,7 @@
 "`P2301R1 <https://wg21.link/P2301R1>`__","LWG","Add a ``pmr`` alias for ``std::stacktrace``","October 2021","",""
 "`P2321R2 <https://wg21.link/P2321R2>`__","LWG","``zip``","October 2021","|In Progress|","","|ranges|"
 "`P2340R1 <https://wg21.link/P2340R1>`__","LWG","Clarifying the status of the 'C headers'","October 2021","",""
-"`P2393R1 <https://wg21.link/P2393R1>`__","LWG","Cleaning up ``integer``-class types","October 2021","",""
+"`P2393R1 <https://wg21.link/P2393R1>`__","LWG","Cleaning up ``integer``-class types","October 2021","|Complete|","18.0"
 "`P2401R0 <https://wg21.link/P2401R0>`__","LWG","Add a conditional ``noexcept`` specification to ``std::exchange``","October 2021","|Complete|","14.0"
 "","","","","","",""
 "`P0323R12 <https://wg21.link/P0323R12>`__","LWG","``std::expected``","February 2022","|Complete|","16.0"
diff --git a/libcxx/include/__ranges/counted.h b/libcxx/include/__ranges/counted.h
index 882f90b1ed82e..ba83543ab4a3e 100644
--- a/libcxx/include/__ranges/counted.h
+++ b/libcxx/include/__ranges/counted.h
@@ -38,12 +38,13 @@ namespace ranges::views {
 namespace __counted {
 
   struct __fn {
-    template<contiguous_iterator _It>
-    _LIBCPP_HIDE_FROM_ABI
-    static constexpr auto __go(_It __it, iter_difference_t<_It> __count)
-      noexcept(noexcept(span(std::to_address(__it), static_cast<size_t>(__count))))
-      // Deliberately omit return-type SFINAE, because to_address is not SFINAE-friendly
-      { return          span(std::to_address(__it), static_cast<size_t>(__count)); }
+    template <contiguous_iterator _It>
+    _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_It __it, iter_difference_t<_It> __count) noexcept(
+        noexcept(span(std::to_address(__it), static_cast<size_t>(static_cast<iter_difference_t<_It>>(__count)))))
+    // Deliberately omit return-type SFINAE, because to_address is not SFINAE-friendly
+    {
+      return span(std::to_address(__it), static_cast<size_t>(static_cast<iter_difference_t<_It>>(__count)));
+    }
 
     template<random_access_iterator _It>
     _LIBCPP_HIDE_FROM_ABI
diff --git a/libcxx/include/__ranges/subrange.h b/libcxx/include/__ranges/subrange.h
index 75f9284a582ff..1bc41a75e2128 100644
--- a/libcxx/include/__ranges/subrange.h
+++ b/libcxx/include/__ranges/subrange.h
@@ -122,15 +122,12 @@ namespace ranges {
       : subrange(ranges::begin(__range), ranges::end(__range))
     { }
 
-    template<__different_from<subrange> _Range>
-      requires borrowed_range<_Range> &&
-               __convertible_to_non_slicing<iterator_t<_Range>, _Iter> &&
+    template <__different_from<subrange> _Range>
+      requires borrowed_range<_Range> && __convertible_to_non_slicing<iterator_t<_Range>, _Iter> &&
                convertible_to<sentinel_t<_Range>, _Sent>
-    _LIBCPP_HIDE_FROM_ABI
-    constexpr subrange(_Range&& __range)
-      requires _StoreSize && sized_range<_Range>
-      : subrange(__range, ranges::size(__range))
-    { }
+               _LIBCPP_HIDE_FROM_ABI constexpr subrange(_Range&& __range)
+                 requires _StoreSize && sized_range<_Range>
+        : subrange(__range, static_cast<decltype(__size_)>(ranges::size(__range))) {}
 
     template<borrowed_range _Range>
       requires __convertible_to_non_slicing<iterator_t<_Range>, _Iter> &&
diff --git a/libcxx/include/__ranges/take_view.h b/libcxx/include/__ranges/take_view.h
index 518375d684abd..229ba72ced31c 100644
--- a/libcxx/include/__ranges/take_view.h
+++ b/libcxx/include/__ranges/take_view.h
@@ -87,7 +87,7 @@ class take_view : public view_interface<take_view<_View>> {
         return ranges::begin(__base_);
       } else {
         using _DifferenceT = range_difference_t<_View>;
-        auto __size = size();
+        auto __size        = range_difference_t<_View>(size());
         return counted_iterator(ranges::begin(__base_), static_cast<_DifferenceT>(__size));
       }
     } else {
@@ -102,7 +102,7 @@ class take_view : public view_interface<take_view<_View>> {
         return ranges::begin(__base_);
       } else {
         using _DifferenceT = range_difference_t<const _View>;
-        auto __size = size();
+        auto __size        = range_difference_t<_View>(size());
         return counted_iterator(ranges::begin(__base_), static_cast<_DifferenceT>(__size));
       }
     } else {
@@ -114,7 +114,7 @@ class take_view : public view_interface<take_view<_View>> {
   constexpr auto end() requires (!__simple_view<_View>) {
     if constexpr (sized_range<_View>) {
       if constexpr (random_access_range<_View>) {
-        return ranges::begin(__base_) + size();
+        return ranges::begin(__base_) + range_difference_t<_View>(size());
       } else {
         return default_sentinel;
       }
@@ -127,7 +127,7 @@ class take_view : public view_interface<take_view<_View>> {
   constexpr auto end() const requires range<const _View> {
     if constexpr (sized_range<const _View>) {
       if constexpr (random_access_range<const _View>) {
-        return ranges::begin(__base_) + size();
+        return ranges::begin(__base_) + range_difference_t<_View>(size());
       } else {
         return default_sentinel;
       }

>From 44a02f11dd09d8ddd92369c03f2c7fdf09b1e4f4 Mon Sep 17 00:00:00 2001
From: Christopher Di Bella <cjdb at google.com>
Date: Wed, 13 Dec 2023 20:15:49 +0000
Subject: [PATCH 2/6] adds test for `__int128` and `_BitInt(N)`

---
 .../iterator.concepts/incrementable.h         |  10 ++
 .../weakly_incrementable.compile.pass.cpp     | 132 ++++++++++++++++++
 2 files changed, 142 insertions(+)

diff --git a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/incrementable.h b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/incrementable.h
index 16eddd6f06e69..16e7bf040c646 100644
--- a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/incrementable.h
+++ b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/incrementable.h
@@ -9,6 +9,8 @@
 #ifndef LIBCPP_TEST_STD_ITERATORS_ITERATOR_REQUIREMENTS_ITERATOR_CONCEPTS_INCREMENTABLE_H
 #define LIBCPP_TEST_STD_ITERATORS_ITERATOR_REQUIREMENTS_ITERATOR_CONCEPTS_INCREMENTABLE_H
 
+#include <concepts>
+
 struct postfix_increment_returns_void {
   using difference_type = int;
   postfix_increment_returns_void& operator++();
@@ -181,4 +183,12 @@ struct noncopyable_with_difference_type_and_minus {
   bool operator==(noncopyable_with_difference_type_and_minus const&) const;
 };
 
+template <std::signed_integral T>
+struct extended_integral_difference_type {
+  using difference_type = T;
+
+  extended_integral_difference_type& operator++();
+  void operator++(int);
+};
+
 #endif // #define LIBCPP_TEST_STD_ITERATORS_ITERATOR_REQUIREMENTS_ITERATOR_CONCEPTS_INCREMENTABLE_H
diff --git a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.winc/weakly_incrementable.compile.pass.cpp b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.winc/weakly_incrementable.compile.pass.cpp
index 22b3ae94e5fc3..c37c6d7e6e707 100644
--- a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.winc/weakly_incrementable.compile.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.winc/weakly_incrementable.compile.pass.cpp
@@ -18,6 +18,7 @@
 #include <optional>
 
 #include "../incrementable.h"
+#include "test_macros.h"
 
 static_assert(std::weakly_incrementable<int>);
 static_assert(std::weakly_incrementable<int*>);
@@ -67,3 +68,134 @@ static_assert(std::weakly_incrementable<difference_type_and_void_minus>);
 static_assert(std::weakly_incrementable<noncopyable_with_difference_type>);
 static_assert(std::weakly_incrementable<noncopyable_without_difference_type>);
 static_assert(std::weakly_incrementable<noncopyable_with_difference_type_and_minus>);
+
+#if !defined(TEST_HAS_NO_INT128)
+static_assert(std::weakly_incrementable<extended_integral_difference_type<__int128>>);
+#endif
+
+#if defined(__BIT_TYPES_DEFINED__)
+#  pragma GCC diagnostic push
+#  pragma GCC diagnostic ignored "-Wbit-int-extension"
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(8)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(9)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(10)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(11)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(12)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(13)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(14)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(15)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(16)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(17)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(18)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(19)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(20)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(21)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(22)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(23)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(24)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(25)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(26)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(27)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(28)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(29)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(30)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(31)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(32)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(33)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(34)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(35)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(36)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(37)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(38)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(39)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(40)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(41)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(42)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(43)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(44)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(45)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(46)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(47)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(48)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(49)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(50)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(51)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(52)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(53)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(54)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(55)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(56)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(57)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(58)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(59)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(60)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(61)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(62)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(63)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(64)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(65)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(66)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(67)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(68)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(69)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(70)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(71)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(72)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(73)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(74)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(75)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(76)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(77)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(78)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(79)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(80)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(81)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(82)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(83)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(84)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(85)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(86)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(87)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(88)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(89)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(90)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(91)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(92)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(93)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(94)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(95)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(96)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(97)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(98)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(99)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(100)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(101)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(102)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(103)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(104)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(105)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(106)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(107)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(108)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(109)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(110)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(111)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(112)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(113)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(114)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(115)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(116)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(117)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(118)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(119)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(120)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(121)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(122)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(123)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(124)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(125)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(126)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(127)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(128)>>);
+#  pragma GCC diagnostic pop
+#endif

>From 783dba7cfa323994c5b542486ac247227d4dd59e Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 21 Oct 2026 15:11:10 +0800
Subject: [PATCH 3/6] Re-target LLVM 24

---
 libcxx/docs/ReleaseNotes/24.rst    | 1 +
 libcxx/docs/Status/Cxx23Papers.csv | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/docs/ReleaseNotes/24.rst b/libcxx/docs/ReleaseNotes/24.rst
index 04f02ab66a773..0217343737a2a 100644
--- a/libcxx/docs/ReleaseNotes/24.rst
+++ b/libcxx/docs/ReleaseNotes/24.rst
@@ -57,6 +57,7 @@ Implemented Papers
 - P3450R1: Extend ``std::is_within_lifetime`` (`Github <https://llvm.org/PR189610>`__)
 - P3793R2: Better shifting (`Github <https://llvm.org/PR219389>`__) (no ``std::simd`` overloads)
 - P0040R3: Extending memory management tools (`Github <https://github.com/llvm/llvm-project/issues/103640>`__)
+- P2393R1: Cleaning up ``integer``-class types (`Github <https://github.com/llvm/llvm-project/issues/105171>`__)
 
 Improvements and New Features
 -----------------------------
diff --git a/libcxx/docs/Status/Cxx23Papers.csv b/libcxx/docs/Status/Cxx23Papers.csv
index 4ae6ab91d8228..c7a2aeae67da4 100644
--- a/libcxx/docs/Status/Cxx23Papers.csv
+++ b/libcxx/docs/Status/Cxx23Papers.csv
@@ -35,7 +35,7 @@
 "`P2301R1 <https://wg21.link/P2301R1>`__","Add a ``pmr`` alias for ``std::stacktrace``","2021-10 (Virtual)","","","`#105167 <https://github.com/llvm/llvm-project/issues/105167>`__",""
 "`P2321R2 <https://wg21.link/P2321R2>`__","``zip``","2021-10 (Virtual)","|Complete|","22","`#105169 <https://github.com/llvm/llvm-project/issues/105169>`__",""
 "`P2340R1 <https://wg21.link/P2340R1>`__","Clarifying the status of the 'C headers'","2021-10 (Virtual)","|Nothing To Do|","","`#105170 <https://github.com/llvm/llvm-project/issues/105170>`__",""
-"`P2393R1 <https://wg21.link/P2393R1>`__","Cleaning up ``integer``-class types","2021-10 (Virtual)","|Complete|","22","`#105171 <https://github.com/llvm/llvm-project/issues/105171>`__",""
+"`P2393R1 <https://wg21.link/P2393R1>`__","Cleaning up ``integer``-class types","2021-10 (Virtual)","|Complete|","24","`#105171 <https://github.com/llvm/llvm-project/issues/105171>`__",""
 "`P2401R0 <https://wg21.link/P2401R0>`__","Add a conditional ``noexcept`` specification to ``std::exchange``","2021-10 (Virtual)","|Complete|","14","`#105172 <https://github.com/llvm/llvm-project/issues/105172>`__",""
 "","","","","","",""
 "`P0323R12 <https://wg21.link/P0323R12>`__","``std::expected``","2022-02 (Virtual)","|Complete|","16","`#105173 <https://github.com/llvm/llvm-project/issues/105173>`__",""

>From 5ff9efb97cb3e6f23bfcd43e6f312b176488bbb6 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 21 Oct 2026 15:16:41 +0800
Subject: [PATCH 4/6] Modernize test coverage for `_BitInt`

---
 .../weakly_incrementable.compile.pass.cpp                | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.winc/weakly_incrementable.compile.pass.cpp b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.winc/weakly_incrementable.compile.pass.cpp
index c37c6d7e6e707..adf780ce7c420 100644
--- a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.winc/weakly_incrementable.compile.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.winc/weakly_incrementable.compile.pass.cpp
@@ -73,9 +73,7 @@ static_assert(std::weakly_incrementable<noncopyable_with_difference_type_and_min
 static_assert(std::weakly_incrementable<extended_integral_difference_type<__int128>>);
 #endif
 
-#if defined(__BIT_TYPES_DEFINED__)
-#  pragma GCC diagnostic push
-#  pragma GCC diagnostic ignored "-Wbit-int-extension"
+#if TEST_HAS_BITINT
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(8)>>);
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(9)>>);
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(10)>>);
@@ -133,6 +131,7 @@ static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitIn
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(62)>>);
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(63)>>);
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(64)>>);
+#  if __BITINT_MAXWIDTH__ >= 96
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(65)>>);
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(66)>>);
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(67)>>);
@@ -165,6 +164,8 @@ static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitIn
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(94)>>);
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(95)>>);
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(96)>>);
+#  endif
+#  if __BITINT_MAXWIDTH__ >= 128
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(97)>>);
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(98)>>);
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(99)>>);
@@ -197,5 +198,5 @@ static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitIn
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(126)>>);
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(127)>>);
 static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(128)>>);
-#  pragma GCC diagnostic pop
+#  endif
 #endif

>From ebb2eb781d22df1cd3b22aefcb5561542a5ec6c0 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 21 Oct 2026 15:20:47 +0800
Subject: [PATCH 5/6] Make test random iterators more pedantic in arithmetic

This rejects arithmetic between test random access iterators with
non-difference-typed integers, covering fixes for `take_view::end`.
---
 libcxx/test/support/test_iterators.h | 252 +++++++++++++++++++--------
 1 file changed, 177 insertions(+), 75 deletions(-)

diff --git a/libcxx/test/support/test_iterators.h b/libcxx/test/support/test_iterators.h
index de55afa497834..0a12ef8b3ada1 100644
--- a/libcxx/test/support/test_iterators.h
+++ b/libcxx/test/support/test_iterators.h
@@ -248,19 +248,44 @@ class random_access_iterator
     }
 
     TEST_CONSTEXPR_CXX14 reference operator*() const {return *it_;}
-    TEST_CONSTEXPR_CXX14 reference operator[](difference_type n) const {return it_[n];}
+    template <class I, typename std::enable_if<std::is_same<I, difference_type>::value, int>::type = 0>
+    TEST_CONSTEXPR_CXX14 reference operator[](I n) const {
+      return it_[n];
+    }
 
     TEST_CONSTEXPR_CXX14 random_access_iterator& operator++() {++it_; return *this;}
     TEST_CONSTEXPR_CXX14 random_access_iterator& operator--() {--it_; return *this;}
     TEST_CONSTEXPR_CXX14 random_access_iterator operator++(int) {return random_access_iterator(it_++);}
     TEST_CONSTEXPR_CXX14 random_access_iterator operator--(int) {return random_access_iterator(it_--);}
 
-    TEST_CONSTEXPR_CXX14 random_access_iterator& operator+=(difference_type n) {it_ += n; return *this;}
-    TEST_CONSTEXPR_CXX14 random_access_iterator& operator-=(difference_type n) {it_ -= n; return *this;}
-    friend TEST_CONSTEXPR_CXX14 random_access_iterator operator+(random_access_iterator x, difference_type n) {x += n; return x;}
-    friend TEST_CONSTEXPR_CXX14 random_access_iterator operator+(difference_type n, random_access_iterator x) {x += n; return x;}
-    friend TEST_CONSTEXPR_CXX14 random_access_iterator operator-(random_access_iterator x, difference_type n) {x -= n; return x;}
-    friend TEST_CONSTEXPR difference_type operator-(random_access_iterator x, random_access_iterator y) {return x.it_ - y.it_;}
+    template <class I, typename std::enable_if<std::is_same<I, difference_type>::value, int>::type = 0>
+    TEST_CONSTEXPR_CXX14 random_access_iterator& operator+=(I n) {
+      it_ += n;
+      return *this;
+    }
+    template <class I, typename std::enable_if<std::is_same<I, difference_type>::value, int>::type = 0>
+    TEST_CONSTEXPR_CXX14 random_access_iterator& operator-=(I n) {
+      it_ -= n;
+      return *this;
+    }
+    template <class I, typename std::enable_if<std::is_same<I, difference_type>::value, int>::type = 0>
+    friend TEST_CONSTEXPR_CXX14 random_access_iterator operator+(random_access_iterator x, I n) {
+      x += n;
+      return x;
+    }
+    template <class I, typename std::enable_if<std::is_same<I, difference_type>::value, int>::type = 0>
+    friend TEST_CONSTEXPR_CXX14 random_access_iterator operator+(I n, random_access_iterator x) {
+      x += n;
+      return x;
+    }
+    template <class I, typename std::enable_if<std::is_same<I, difference_type>::value, int>::type = 0>
+    friend TEST_CONSTEXPR_CXX14 random_access_iterator operator-(random_access_iterator x, I n) {
+      x -= n;
+      return x;
+    }
+    friend TEST_CONSTEXPR difference_type operator-(random_access_iterator x, random_access_iterator y) {
+      return x.it_ - y.it_;
+    }
 
     friend TEST_CONSTEXPR bool operator==(const random_access_iterator& x, const random_access_iterator& y) {return x.it_ == y.it_;}
     friend TEST_CONSTEXPR bool operator!=(const random_access_iterator& x, const random_access_iterator& y) {return x.it_ != y.it_;}
@@ -313,7 +338,10 @@ class three_way_random_access_iterator {
   }
 
   TEST_CONSTEXPR_CXX14 reference operator*() const { return *it_; }
-  TEST_CONSTEXPR_CXX14 reference operator[](difference_type n) const { return it_[n]; }
+  template <class I, typename std::enable_if<std::is_same<I, difference_type>::value, int>::type = 0>
+  TEST_CONSTEXPR_CXX14 reference operator[](I n) const {
+    return it_[n];
+  }
 
   TEST_CONSTEXPR_CXX14 three_way_random_access_iterator& operator++() {
     ++it_;
@@ -330,26 +358,28 @@ class three_way_random_access_iterator {
     return three_way_random_access_iterator(it_--);
   }
 
-  TEST_CONSTEXPR_CXX14 three_way_random_access_iterator& operator+=(difference_type n) {
+  template <class I, typename std::enable_if<std::is_same<I, difference_type>::value, int>::type = 0>
+  TEST_CONSTEXPR_CXX14 three_way_random_access_iterator& operator+=(I n) {
     it_ += n;
     return *this;
   }
-  TEST_CONSTEXPR_CXX14 three_way_random_access_iterator& operator-=(difference_type n) {
+  template <class I, typename std::enable_if<std::is_same<I, difference_type>::value, int>::type = 0>
+  TEST_CONSTEXPR_CXX14 three_way_random_access_iterator& operator-=(I n) {
     it_ -= n;
     return *this;
   }
-  friend TEST_CONSTEXPR_CXX14 three_way_random_access_iterator
-  operator+(three_way_random_access_iterator x, difference_type n) {
+  template <class I, typename std::enable_if<std::is_same<I, difference_type>::value, int>::type = 0>
+  friend TEST_CONSTEXPR_CXX14 three_way_random_access_iterator operator+(three_way_random_access_iterator x, I n) {
     x += n;
     return x;
   }
-  friend TEST_CONSTEXPR_CXX14 three_way_random_access_iterator
-  operator+(difference_type n, three_way_random_access_iterator x) {
+  template <class I, typename std::enable_if<std::is_same<I, difference_type>::value, int>::type = 0>
+  friend TEST_CONSTEXPR_CXX14 three_way_random_access_iterator operator+(I n, three_way_random_access_iterator x) {
     x += n;
     return x;
   }
-  friend TEST_CONSTEXPR_CXX14 three_way_random_access_iterator
-  operator-(three_way_random_access_iterator x, difference_type n) {
+  template <class I, typename std::enable_if<std::is_same<I, difference_type>::value, int>::type = 0>
+  friend TEST_CONSTEXPR_CXX14 three_way_random_access_iterator operator-(three_way_random_access_iterator x, I n) {
     x -= n;
     return x;
   }
@@ -443,7 +473,10 @@ class cpp20_random_access_iterator {
   }
 
   constexpr decltype(auto) operator*() const { return *it_; }
-  constexpr decltype(auto) operator[](difference_type n) const { return it_[n]; }
+  template <std::same_as<difference_type> I>
+  constexpr decltype(auto) operator[](I n) const {
+    return it_[n];
+  }
 
   constexpr cpp20_random_access_iterator& operator++() {
     ++it_;
@@ -456,23 +489,28 @@ class cpp20_random_access_iterator {
   constexpr cpp20_random_access_iterator operator++(int) { return cpp20_random_access_iterator(it_++); }
   constexpr cpp20_random_access_iterator operator--(int) { return cpp20_random_access_iterator(it_--); }
 
-  constexpr cpp20_random_access_iterator& operator+=(difference_type n) {
+  template <std::same_as<difference_type> I>
+  constexpr cpp20_random_access_iterator& operator+=(I n) {
     it_ += n;
     return *this;
   }
-  constexpr cpp20_random_access_iterator& operator-=(difference_type n) {
+  template <std::same_as<difference_type> I>
+  constexpr cpp20_random_access_iterator& operator-=(I n) {
     it_ -= n;
     return *this;
   }
-  friend constexpr cpp20_random_access_iterator operator+(cpp20_random_access_iterator x, difference_type n) {
+  template <std::same_as<difference_type> I>
+  friend constexpr cpp20_random_access_iterator operator+(cpp20_random_access_iterator x, I n) {
     x += n;
     return x;
   }
-  friend constexpr cpp20_random_access_iterator operator+(difference_type n, cpp20_random_access_iterator x) {
+  template <std::same_as<difference_type> I>
+  friend constexpr cpp20_random_access_iterator operator+(I n, cpp20_random_access_iterator x) {
     x += n;
     return x;
   }
-  friend constexpr cpp20_random_access_iterator operator-(cpp20_random_access_iterator x, difference_type n) {
+  template <std::same_as<difference_type> I>
+  friend constexpr cpp20_random_access_iterator operator-(cpp20_random_access_iterator x, I n) {
     x -= n;
     return x;
   }
@@ -543,7 +581,10 @@ class contiguous_iterator {
 
   constexpr reference operator*() const { return *it_; }
   constexpr pointer operator->() const { return it_; }
-  constexpr reference operator[](difference_type n) const { return it_[n]; }
+  template <std::same_as<difference_type> I>
+  constexpr reference operator[](I n) const {
+    return it_[n];
+  }
 
   constexpr contiguous_iterator& operator++() {
     ++it_;
@@ -556,23 +597,28 @@ class contiguous_iterator {
   constexpr contiguous_iterator operator++(int) { return contiguous_iterator(it_++); }
   constexpr contiguous_iterator operator--(int) { return contiguous_iterator(it_--); }
 
-  constexpr contiguous_iterator& operator+=(difference_type n) {
+  template <std::same_as<difference_type> I>
+  constexpr contiguous_iterator& operator+=(I n) {
     it_ += n;
     return *this;
   }
-  constexpr contiguous_iterator& operator-=(difference_type n) {
+  template <std::same_as<difference_type> I>
+  constexpr contiguous_iterator& operator-=(I n) {
     it_ -= n;
     return *this;
   }
-  friend constexpr contiguous_iterator operator+(contiguous_iterator x, difference_type n) {
+  template <std::same_as<difference_type> I>
+  friend constexpr contiguous_iterator operator+(contiguous_iterator x, I n) {
     x += n;
     return x;
   }
-  friend constexpr contiguous_iterator operator+(difference_type n, contiguous_iterator x) {
+  template <std::same_as<difference_type> I>
+  friend constexpr contiguous_iterator operator+(I n, contiguous_iterator x) {
     x += n;
     return x;
   }
-  friend constexpr contiguous_iterator operator-(contiguous_iterator x, difference_type n) {
+  template <std::same_as<difference_type> I>
+  friend constexpr contiguous_iterator operator-(contiguous_iterator x, I n) {
     x -= n;
     return x;
   }
@@ -640,18 +686,41 @@ class three_way_contiguous_iterator
 
     constexpr reference operator*() const {return *it_;}
     constexpr pointer operator->() const {return it_;}
-    constexpr reference operator[](difference_type n) const {return it_[n];}
+    template <std::same_as<difference_type> I>
+    constexpr reference operator[](I n) const {
+      return it_[n];
+    }
 
     constexpr three_way_contiguous_iterator& operator++() {++it_; return *this;}
     constexpr three_way_contiguous_iterator& operator--() {--it_; return *this;}
     constexpr three_way_contiguous_iterator operator++(int) {return three_way_contiguous_iterator(it_++);}
     constexpr three_way_contiguous_iterator operator--(int) {return three_way_contiguous_iterator(it_--);}
 
-    constexpr three_way_contiguous_iterator& operator+=(difference_type n) {it_ += n; return *this;}
-    constexpr three_way_contiguous_iterator& operator-=(difference_type n) {it_ -= n; return *this;}
-    friend constexpr three_way_contiguous_iterator operator+(three_way_contiguous_iterator x, difference_type n) {x += n; return x;}
-    friend constexpr three_way_contiguous_iterator operator+(difference_type n, three_way_contiguous_iterator x) {x += n; return x;}
-    friend constexpr three_way_contiguous_iterator operator-(three_way_contiguous_iterator x, difference_type n) {x -= n; return x;}
+    template <std::same_as<difference_type> I>
+    constexpr three_way_contiguous_iterator& operator+=(I n) {
+      it_ += n;
+      return *this;
+    }
+    template <std::same_as<difference_type> I>
+    constexpr three_way_contiguous_iterator& operator-=(I n) {
+      it_ -= n;
+      return *this;
+    }
+    template <std::same_as<difference_type> I>
+    friend constexpr three_way_contiguous_iterator operator+(three_way_contiguous_iterator x, I n) {
+      x += n;
+      return x;
+    }
+    template <std::same_as<difference_type> I>
+    friend constexpr three_way_contiguous_iterator operator+(I n, three_way_contiguous_iterator x) {
+      x += n;
+      return x;
+    }
+    template <std::same_as<difference_type> I>
+    friend constexpr three_way_contiguous_iterator operator-(three_way_contiguous_iterator x, I n) {
+      x -= n;
+      return x;
+    }
     friend constexpr difference_type operator-(three_way_contiguous_iterator x, three_way_contiguous_iterator y) {return x.it_ - y.it_;}
 
     friend constexpr auto operator<=>(const three_way_contiguous_iterator& x, const three_way_contiguous_iterator& y) {return x.it_ <=> y.it_;}
@@ -998,7 +1067,10 @@ class operation_counting_iterator {
 
     constexpr decltype(auto) operator*() const { return *It(base_); }
 
-    constexpr decltype(auto) operator[](difference_type n) const { return It(base_)[n]; }
+    template <std::same_as<difference_type> I>
+    constexpr decltype(auto) operator[](I n) const {
+      return It(base_)[n];
+    }
 
     constexpr operation_counting_iterator& operator++() {
       It tmp(base_);
@@ -1034,39 +1106,39 @@ class operation_counting_iterator {
       return temp;
     }
 
-    constexpr operation_counting_iterator& operator+=(difference_type const n)
+    template <std::same_as<difference_type> I>
       requires std::random_access_iterator<It>
-    {
+    constexpr operation_counting_iterator& operator+=(const I n) {
       It tmp(base_);
       base_ = base(tmp += n);
       moved_by(n);
       return *this;
     }
 
-    constexpr operation_counting_iterator& operator-=(difference_type const n)
+    template <std::same_as<difference_type> I>
       requires std::random_access_iterator<It>
-    {
+    constexpr operation_counting_iterator& operator-=(const I n) {
       It tmp(base_);
       base_ = base(tmp -= n);
       moved_by(-n);
       return *this;
     }
 
-    friend constexpr operation_counting_iterator operator+(operation_counting_iterator it, difference_type n)
+    template <std::same_as<difference_type> I>
       requires std::random_access_iterator<It>
-    {
+    friend constexpr operation_counting_iterator operator+(operation_counting_iterator it, I n) {
       return it += n;
     }
 
-    friend constexpr operation_counting_iterator operator+(difference_type n, operation_counting_iterator it)
+    template <std::same_as<difference_type> I>
       requires std::random_access_iterator<It>
-    {
+    friend constexpr operation_counting_iterator operator+(I n, operation_counting_iterator it) {
       return it += n;
     }
 
-    friend constexpr operation_counting_iterator operator-(operation_counting_iterator it, difference_type n)
+    template <std::same_as<difference_type> I>
       requires std::random_access_iterator<It>
-    {
+    friend constexpr operation_counting_iterator operator-(operation_counting_iterator it, I n) {
       return it -= n;
     }
 
@@ -1239,25 +1311,33 @@ class Iterator {
   constexpr int iter_swaps() const { assert(iter_swaps_); return *iter_swaps_; }
 
   constexpr value_type& operator*() const { return *ptr_; }
-  constexpr reference operator[](difference_type n) const { return ptr_[n]; }
+  template <std::same_as<difference_type> I>
+  constexpr reference operator[](I n) const {
+    return ptr_[n];
+  }
 
-  friend constexpr Iterator operator+(Iterator i, difference_type n) {
+  template <std::same_as<difference_type> I>
+  friend constexpr Iterator operator+(Iterator i, I n) {
     return Iterator(i.ptr_ + n, i.iter_moves_, i.iter_swaps_);
   }
-  friend constexpr Iterator operator+(difference_type n, Iterator i) {
+  template <std::same_as<difference_type> I>
+  friend constexpr Iterator operator+(I n, Iterator i) {
     return i + n;
   }
-  constexpr Iterator operator-(difference_type n) const {
+  template <std::same_as<difference_type> I>
+  constexpr Iterator operator-(I n) const {
     return Iterator(ptr_ - n, iter_moves_, iter_swaps_);
   }
   constexpr difference_type operator-(Iterator rhs) const {
     return ptr_ - rhs.ptr_;
   }
-  constexpr Iterator& operator+=(difference_type n) {
+  template <std::same_as<difference_type> I>
+  constexpr Iterator& operator+=(I n) {
     ptr_ += n;
     return *this;
   }
-  constexpr Iterator& operator-=(difference_type n) {
+  template <std::same_as<difference_type> I>
+  constexpr Iterator& operator-=(I n) {
     ptr_ -= n;
     return *this;
   }
@@ -1336,18 +1416,21 @@ class rvalue_iterator {
     return tmp;
   }
 
-  constexpr rvalue_iterator operator+(difference_type n) const {
+  template <std::same_as<difference_type> I>
+  constexpr rvalue_iterator operator+(I n) const {
     auto tmp = *this;
     tmp.it_ += n;
     return tmp;
   }
 
-  constexpr friend rvalue_iterator operator+(difference_type n, rvalue_iterator iter) {
+  template <std::same_as<difference_type> I>
+  constexpr friend rvalue_iterator operator+(I n, rvalue_iterator iter) {
     iter += n;
     return iter;
   }
 
-  constexpr rvalue_iterator operator-(difference_type n) const {
+  template <std::same_as<difference_type> I>
+  constexpr rvalue_iterator operator-(I n) const {
     auto tmp = *this;
     tmp.it_ -= n;
     return tmp;
@@ -1355,17 +1438,22 @@ class rvalue_iterator {
 
   constexpr difference_type operator-(const rvalue_iterator& other) const { return it_ - other.it_; }
 
-  constexpr rvalue_iterator& operator+=(difference_type n) {
+  template <std::same_as<difference_type> I>
+  constexpr rvalue_iterator& operator+=(I n) {
     it_ += n;
     return *this;
   }
 
-  constexpr rvalue_iterator& operator-=(difference_type n) {
+  template <std::same_as<difference_type> I>
+  constexpr rvalue_iterator& operator-=(I n) {
     it_ -= n;
     return *this;
   }
 
-  constexpr reference operator[](difference_type n) const { return std::move(it_[n]); }
+  template <std::same_as<difference_type> I>
+  constexpr reference operator[](I n) const {
+    return std::move(it_[n]);
+  }
 
   auto operator<=>(const rvalue_iterator&) const noexcept = default;
 
@@ -1627,20 +1715,23 @@ struct ProxyIterator : ProxyIteratorBase<Base> {
   }
 
   // to satisfy random_access_iterator
-  constexpr ProxyIterator& operator+=(difference_type n)
-    requires std::random_access_iterator<Base> {
+  template <std::same_as<difference_type> I>
+    requires std::random_access_iterator<Base>
+  constexpr ProxyIterator& operator+=(I n) {
     base_ += n;
     return *this;
   }
 
-  constexpr ProxyIterator& operator-=(difference_type n)
-    requires std::random_access_iterator<Base> {
+  template <std::same_as<difference_type> I>
+    requires std::random_access_iterator<Base>
+  constexpr ProxyIterator& operator-=(I n) {
     base_ -= n;
     return *this;
   }
 
-  constexpr Proxy<std::iter_reference_t<Base>> operator[](difference_type n) const
-    requires std::random_access_iterator<Base> {
+  template <std::same_as<difference_type> I>
+    requires std::random_access_iterator<Base>
+  constexpr Proxy<std::iter_reference_t<Base>> operator[](I n) const {
     return {base_[n]};
   }
 
@@ -1669,18 +1760,21 @@ struct ProxyIterator : ProxyIteratorBase<Base> {
     return x.base_ <=> y.base_;
   }
 
-  friend constexpr ProxyIterator operator+(const ProxyIterator& x, difference_type n)
-    requires std::random_access_iterator<Base> {
+  template <std::same_as<difference_type> I>
+    requires std::random_access_iterator<Base>
+  friend constexpr ProxyIterator operator+(const ProxyIterator& x, I n) {
     return ProxyIterator{x.base_ + n};
   }
 
-  friend constexpr ProxyIterator operator+(difference_type n, const ProxyIterator& x)
-    requires std::random_access_iterator<Base> {
+  template <std::same_as<difference_type> I>
+    requires std::random_access_iterator<Base>
+  friend constexpr ProxyIterator operator+(I n, const ProxyIterator& x) {
     return ProxyIterator{n + x.base_};
   }
 
-  friend constexpr ProxyIterator operator-(const ProxyIterator& x, difference_type n)
-    requires std::random_access_iterator<Base> {
+  template <std::same_as<difference_type> I>
+    requires std::random_access_iterator<Base>
+  friend constexpr ProxyIterator operator-(const ProxyIterator& x, I n) {
     return ProxyIterator{x.base_ - n};
   }
 
@@ -1775,7 +1869,8 @@ class iterator_wrapper {
   decltype(*iter_) operator*() { return *iter_; }
   decltype(*iter_) operator*() const { return *iter_; }
 
-  decltype(iter_[0]) operator[](difference_type v) const {
+  template <class I, std::enable_if_t<std::is_same_v<I, difference_type>, int> = 0>
+  decltype(iter_[0]) operator[](I v) const {
     return iter_[v];
   }
 
@@ -1801,12 +1896,14 @@ class iterator_wrapper {
     return tmp;
   }
 
-  Derived& operator+=(difference_type i) {
+  template <class I, std::enable_if_t<std::is_same_v<I, difference_type>, int> = 0>
+  Derived& operator+=(I i) {
     iter_ += i;
     return static_cast<Derived&>(*this);
   }
 
-  Derived& operator-=(difference_type i) {
+  template <class I, std::enable_if_t<std::is_same_v<I, difference_type>, int> = 0>
+  Derived& operator-=(I i) {
     iter_ -= i;
     return static_cast<Derived&>(*this);
   }
@@ -1815,17 +1912,22 @@ class iterator_wrapper {
     return lhs.iter_ - rhs.iter_;
   }
 
-  friend Derived operator-(Derived iter, difference_type i) {
+  template <class I, std::enable_if_t<std::is_same_v<I, difference_type>, int> = 0>
+  friend Derived operator-(Derived iter, I i) {
     iter.iter_ -= i;
     return iter;
   }
 
-  friend Derived operator+(Derived iter, difference_type i) {
+  template <class I, std::enable_if_t<std::is_same_v<I, difference_type>, int> = 0>
+  friend Derived operator+(Derived iter, I i) {
     iter.iter_ += i;
     return iter;
   }
 
-  friend Derived operator+(difference_type i, Derived iter) { return iter + i; }
+  template <class I, std::enable_if_t<std::is_same_v<I, difference_type>, int> = 0>
+  friend Derived operator+(I i, Derived iter) {
+    return iter + i;
+  }
 
   friend bool operator==(const iterator_wrapper& lhs, const iterator_wrapper& rhs) { return lhs.iter_ == rhs.iter_; }
   friend bool operator!=(const iterator_wrapper& lhs, const iterator_wrapper& rhs) { return lhs.iter_ != rhs.iter_; }

>From f25a551cec158cdf8a77b04a676adbd1a409d7a8 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 21 Oct 2026 16:24:27 +0800
Subject: [PATCH 6/6] Preliminary fixes in test support headers

---
 .../test/std/ranges/range.adaptors/range_adaptor_types.h | 2 +-
 libcxx/test/support/MinSequenceContainer.h               | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/libcxx/test/std/ranges/range.adaptors/range_adaptor_types.h b/libcxx/test/std/ranges/range.adaptors/range_adaptor_types.h
index 41ca28fa905e4..62a4d85ada734 100644
--- a/libcxx/test/std/ranges/range.adaptors/range_adaptor_types.h
+++ b/libcxx/test/std/ranges/range.adaptors/range_adaptor_types.h
@@ -251,7 +251,7 @@ struct SizedRandomAccessView : IntBufferView {
   constexpr auto begin() const { return iterator(buffer_); }
   constexpr auto end() const { return sized_sentinel<iterator>(iterator(buffer_ + size_)); }
 
-  constexpr decltype(auto) operator[](std::size_t n) const { return *(begin() + n); }
+  constexpr decltype(auto) operator[](std::size_t n) const { return *(begin() + static_cast<std::ptrdiff_t>(n)); }
 };
 static_assert(std::ranges::view<SizedRandomAccessView>);
 static_assert(std::ranges::random_access_range<SizedRandomAccessView>);
diff --git a/libcxx/test/support/MinSequenceContainer.h b/libcxx/test/support/MinSequenceContainer.h
index 55014a117ba8d..423fe5c0b3804 100644
--- a/libcxx/test/support/MinSequenceContainer.h
+++ b/libcxx/test/support/MinSequenceContainer.h
@@ -10,6 +10,7 @@
 #define SUPPORT_MIN_SEQUENCE_CONTAINER_H
 
 #include <initializer_list>
+#include <iterator>
 #include <vector>
 
 #include "test_iterators.h"
@@ -52,8 +53,12 @@ struct MinSequenceContainer {
   TEST_CONSTEXPR_CXX20 iterator begin() { return iterator(data_.data()); }
   TEST_CONSTEXPR_CXX20 const_iterator begin() const { return const_iterator(data_.data()); }
   TEST_CONSTEXPR_CXX20 const_iterator cbegin() const { return const_iterator(data_.data()); }
-  TEST_CONSTEXPR_CXX20 iterator end() { return begin() + size(); }
-  TEST_CONSTEXPR_CXX20 const_iterator end() const { return begin() + size(); }
+  TEST_CONSTEXPR_CXX20 iterator end() {
+    return begin() + static_cast<typename std::iterator_traits<iterator>::difference_type>(size());
+  }
+  TEST_CONSTEXPR_CXX20 const_iterator end() const {
+    return begin() + static_cast<typename std::iterator_traits<const_iterator>::difference_type>(size());
+  }
   TEST_CONSTEXPR_CXX20 const_iterator cend() const { return end(); }
   TEST_CONSTEXPR_CXX20 size_type size() const { return static_cast<size_type>(data_.size()); }
   TEST_CONSTEXPR_CXX20 bool empty() const { return data_.empty(); }



More information about the libcxx-commits mailing list