[libcxx-commits] [libcxx] [libcxx] P2278R4: implement `{basic_, }const_iterator`, and have `cbegin` et. al. return it (PR #99915)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 29 11:18:59 PDT 2024


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/99915

>From fc447a99c5ea66e6c6afe1803b776ac34b0d79a4 Mon Sep 17 00:00:00 2001
From: Nicole Mazzuca <nicole at strega-nil.co>
Date: Mon, 22 Jul 2024 15:39:27 +0200
Subject: [PATCH] [libcxx] P2278R4: const_iterator and c{begin,end}

Implements `basic_const_iterator` and the const accessors.

Does not implement `const_view`

Does not implement changes to `span` and friends.
---
 libcxx/docs/Status/Cxx23Issues.csv            |  14 +-
 libcxx/docs/Status/Cxx23Papers.csv            |   2 +-
 libcxx/docs/Status/Cxx2cIssues.csv            |   2 +-
 libcxx/docs/Status/Cxx2cPapers.csv            |   2 +-
 libcxx/include/CMakeLists.txt                 |   2 +
 .../include/__algorithm/ranges_reverse_copy.h |  10 +-
 libcxx/include/__iterator/const_iterator.h    | 351 ++++++++++++++++++
 libcxx/include/__iterator/reverse_iterator.h  |  13 -
 libcxx/include/__ranges/access.h              |  55 ---
 libcxx/include/__ranges/concepts.h            |  13 +
 libcxx/include/__ranges/const_access.h        | 222 +++++++++++
 libcxx/include/__ranges/rbegin.h              |  28 --
 libcxx/include/__ranges/rend.h                |  27 --
 libcxx/include/__ranges/view_interface.h      |  22 ++
 libcxx/include/iterator                       |  29 ++
 libcxx/include/module.modulemap               |   2 +
 libcxx/include/ranges                         |  10 +
 libcxx/include/version                        |   4 +-
 libcxx/modules/std/iterator.inc               |  15 +-
 libcxx/modules/std/ranges.inc                 |  14 +-
 .../iterators/const.iterators/alias.pass.cpp  |  32 ++
 .../const.iterators/iterator.pass.cpp         | 139 +++++++
 .../ranges.version.compile.pass.cpp           |  10 +-
 .../version.version.compile.pass.cpp          |  10 +-
 .../std/ranges/range.access/begin.pass.cpp    | 160 ++++----
 .../std/ranges/range.access/cbegin.pass.cpp   | 207 +++++++++++
 .../std/ranges/range.access/cbegin.verify.cpp |  25 ++
 .../std/ranges/range.access/cend.pass.cpp     | 207 +++++++++++
 .../std/ranges/range.access/cend.verify.cpp   |  25 ++
 .../test/std/ranges/range.access/end.pass.cpp | 159 ++++----
 .../std/ranges/range.access/rbegin.pass.cpp   | 233 +++++++-----
 .../std/ranges/range.access/rend.pass.cpp     | 227 ++++++-----
 .../view.interface/view.interface.pass.cpp    |  22 +-
 .../generate_feature_test_macro_components.py |   3 +-
 34 files changed, 1833 insertions(+), 463 deletions(-)
 create mode 100644 libcxx/include/__iterator/const_iterator.h
 create mode 100644 libcxx/include/__ranges/const_access.h
 create mode 100644 libcxx/test/std/iterators/const.iterators/alias.pass.cpp
 create mode 100644 libcxx/test/std/iterators/const.iterators/iterator.pass.cpp
 create mode 100644 libcxx/test/std/ranges/range.access/cbegin.pass.cpp
 create mode 100644 libcxx/test/std/ranges/range.access/cbegin.verify.cpp
 create mode 100644 libcxx/test/std/ranges/range.access/cend.pass.cpp
 create mode 100644 libcxx/test/std/ranges/range.access/cend.verify.cpp

diff --git a/libcxx/docs/Status/Cxx23Issues.csv b/libcxx/docs/Status/Cxx23Issues.csv
index da4cce6eac0c90..6c4deb4d4ad9df 100644
--- a/libcxx/docs/Status/Cxx23Issues.csv
+++ b/libcxx/docs/Status/Cxx23Issues.csv
@@ -219,9 +219,9 @@
 "`LWG3761 <https://wg21.link/LWG3761>`__","``cartesian_product_view::iterator::operator-`` should pass by reference","2022-11 (Kona)","","",""
 "`LWG3762 <https://wg21.link/LWG3762>`__","``generator::iterator::operator==`` should pass by reference","2022-11 (Kona)","","",""
 "`LWG3764 <https://wg21.link/LWG3764>`__","``reference_wrapper::operator()`` should propagate noexcept","2022-11 (Kona)","|Complete|","17.0",""
-"`LWG3765 <https://wg21.link/LWG3765>`__","``const_sentinel`` should be constrained","2022-11 (Kona)","","",""
-"`LWG3766 <https://wg21.link/LWG3766>`__","``view_interface::cbegin`` is underconstrained","2022-11 (Kona)","","",""
-"`LWG3770 <https://wg21.link/LWG3770>`__","``const_sentinel_t`` is missing","2022-11 (Kona)","","",""
+"`LWG3765 <https://wg21.link/LWG3765>`__","``const_sentinel`` should be constrained","2022-11 (Kona)","|Complete|","20.0",""
+"`LWG3766 <https://wg21.link/LWG3766>`__","``view_interface::cbegin`` is underconstrained","2022-11 (Kona)","|Complete|","20.0",""
+"`LWG3770 <https://wg21.link/LWG3770>`__","``const_sentinel_t`` is missing","2022-11 (Kona)","|Complete|","20.0",""
 "`LWG3773 <https://wg21.link/LWG3773>`__","``views::zip_transform`` still requires ``F`` to be ``copy_constructible`` when empty pack","2022-11 (Kona)","","",""
 "`LWG3774 <https://wg21.link/LWG3774>`__","``<flat_set>`` should include ``<compare>``","2022-11 (Kona)","","",""
 "`LWG3775 <https://wg21.link/LWG3775>`__","Broken dependencies in the ``Cpp17Allocator`` requirements","2022-11 (Kona)","","",""
@@ -252,7 +252,7 @@
 "`LWG3664 <https://wg21.link/LWG3664>`__","`LWG 3392 <https://wg21.link/LWG3392>`__ ``broke std::ranges::distance(a, a+3)``","2023-02 (Issaquah)","","",""
 "`LWG3720 <https://wg21.link/LWG3720>`__","Restrict the valid types of ``arg-id`` for width and precision in ``std-format-spec``","2023-02 (Issaquah)","|Complete|","17.0",""
 "`LWG3756 <https://wg21.link/LWG3756>`__","Is the ``std::atomic_flag`` class signal-safe?","2023-02 (Issaquah)","","",""
-"`LWG3769 <https://wg21.link/LWG3769>`__","``basic_const_iterator::operator==`` causes infinite constraint recursion","2023-02 (Issaquah)","","",""
+"`LWG3769 <https://wg21.link/LWG3769>`__","``basic_const_iterator::operator==`` causes infinite constraint recursion","2023-02 (Issaquah)","|Complete|","20.0",""
 "`LWG3807 <https://wg21.link/LWG3807>`__","The feature test macro for ``ranges::find_last`` should be renamed","2023-02 (Issaquah)","","",""
 "`LWG3811 <https://wg21.link/LWG3811>`__","``views::as_const`` on ``ref_view<T>`` should return ``ref_view<const T>``","2023-02 (Issaquah)","","",""
 "`LWG3820 <https://wg21.link/LWG3820>`__","``cartesian_product_view::iterator::prev`` is not quite right","2023-02 (Issaquah)","","",""
@@ -271,7 +271,7 @@
 "`LWG3849 <https://wg21.link/LWG3849>`__","``cartesian_product_view::iterator``'s default constructor is overconstrained","2023-02 (Issaquah)","","",""
 "`LWG3850 <https://wg21.link/LWG3850>`__","``views::as_const`` on ``empty_view<T>`` should return ``empty_view<const T>``","2023-02 (Issaquah)","","",""
 "`LWG3851 <https://wg21.link/LWG3851>`__","``chunk_view::inner-iterator`` missing custom ``iter_move`` and ``iter_swap``","2023-02 (Issaquah)","","",""
-"`LWG3853 <https://wg21.link/LWG3853>`__","``basic_const_iterator<volatile int*>::operator->`` is ill-formed","2023-02 (Issaquah)","","",""
+"`LWG3853 <https://wg21.link/LWG3853>`__","``basic_const_iterator<volatile int*>::operator->`` is ill-formed","2023-02 (Issaquah)","|Complete|","20.0",""
 "`LWG3857 <https://wg21.link/LWG3857>`__","``basic_string_view`` should allow explicit conversion when only traits vary","2023-02 (Issaquah)","|Complete|","17.0",""
 "`LWG3860 <https://wg21.link/LWG3860>`__","``range_common_reference_t`` is missing","2023-02 (Issaquah)","|Complete|","17.0",""
 "`LWG3866 <https://wg21.link/LWG3866>`__","Bad Mandates for ``expected::transform_error`` overloads","2023-02 (Issaquah)","|Complete|","17.0",""
@@ -293,12 +293,12 @@
 "`LWG3836 <https://wg21.link/LWG3836>`__","``std::expected<bool, E1>`` conversion constructor ``expected(const expected<U, G>&)`` should take precedence over ``expected(U&&)`` with operator ``bool``","2023-02 (Issaquah)","|Complete|","18.0",""
 "`LWG3843 <https://wg21.link/LWG3843>`__","``std::expected<T,E>::value() &`` assumes ``E`` is copy constructible","2023-02 (Issaquah)","|Complete|","17.0",""
 "`LWG3847 <https://wg21.link/LWG3847>`__","``ranges::to`` can still return views","2023-02 (Issaquah)","|Complete|","17.0",""
-"`LWG3862 <https://wg21.link/LWG3862>`__","``basic_const_iterator``'s ``common_type`` specialization is underconstrained","2023-02 (Issaquah)","","",""
+"`LWG3862 <https://wg21.link/LWG3862>`__","``basic_const_iterator``'s ``common_type`` specialization is underconstrained","2023-02 (Issaquah)","|Complete|","20.0",""
 "`LWG3865 <https://wg21.link/LWG3865>`__","Sorting a range of ``pairs``","2023-02 (Issaquah)","|Complete|","17.0",""
 "`LWG3869 <https://wg21.link/LWG3869>`__","Deprecate ``std::errc`` constants related to UNIX STREAMS","2023-02 (Issaquah)","|Complete|","19.0",""
 "`LWG3870 <https://wg21.link/LWG3870>`__","Remove ``voidify``","2023-02 (Issaquah)","","",""
 "`LWG3871 <https://wg21.link/LWG3871>`__","Adjust note about ``terminate``","2023-02 (Issaquah)","","",""
-"`LWG3872 <https://wg21.link/LWG3872>`__","``basic_const_iterator`` should have custom ``iter_move``","2023-02 (Issaquah)","","",""
+"`LWG3872 <https://wg21.link/LWG3872>`__","``basic_const_iterator`` should have custom ``iter_move``","2023-02 (Issaquah)","|Complete|","20.0",""
 "`LWG3875 <https://wg21.link/LWG3875>`__","``std::ranges::repeat_view<T, IntegerClass>::iterator`` may be ill-formed","2023-02 (Issaquah)","|Complete|","17.0",""
 "`LWG3876 <https://wg21.link/LWG3876>`__","Default constructor of ``std::layout_XX::mapping`` misses precondition","2023-02 (Issaquah)","","",""
 "`LWG3877 <https://wg21.link/LWG3877>`__","Incorrect constraints on ``const``-qualified monadic overloads for ``std::expected``","2023-02 (Issaquah)","|Complete|","17.0",""
diff --git a/libcxx/docs/Status/Cxx23Papers.csv b/libcxx/docs/Status/Cxx23Papers.csv
index 2c8a91d8401b53..1668016074c700 100644
--- a/libcxx/docs/Status/Cxx23Papers.csv
+++ b/libcxx/docs/Status/Cxx23Papers.csv
@@ -61,7 +61,7 @@
 "`P1899R3 <https://wg21.link/P1899R3>`__","``stride_view``","2022-07 (Virtual)","","",""
 "`P2093R14 <https://wg21.link/P2093R14>`__","Formatted output","2022-07 (Virtual)","|Complete|","18.0",""
 "`P2165R4 <https://wg21.link/P2165R4>`__","Compatibility between ``tuple``, ``pair`` and ``tuple-like`` objects","2022-07 (Virtual)","","",""
-"`P2278R4 <https://wg21.link/P2278R4>`__","``cbegin`` should always return a constant iterator","2022-07 (Virtual)","","",""
+"`P2278R4 <https://wg21.link/P2278R4>`__","``cbegin`` should always return a constant iterator","2022-07 (Virtual)","|Complete|","20.0","This paper is applied as DR against C++23 (MSVC STL and libstdc++ have done the same). The feature macro is not yet defined, since other features from the original paper have not been completed."
 "`P2286R8 <https://wg21.link/P2286R8>`__","Formatting Ranges","2022-07 (Virtual)","|Complete|","16.0",""
 "`P2291R3 <https://wg21.link/P2291R3>`__","Add Constexpr Modifiers to Functions ``to_chars`` and ``from_chars`` for Integral Types in ``<charconv>`` Header","2022-07 (Virtual)","|Complete|","16.0",""
 "`P2302R4 <https://wg21.link/P2302R4>`__","``std::ranges::contains``","2022-07 (Virtual)","|Complete|","19.0",""
diff --git a/libcxx/docs/Status/Cxx2cIssues.csv b/libcxx/docs/Status/Cxx2cIssues.csv
index 14633265a42251..88fd557cc80b3e 100644
--- a/libcxx/docs/Status/Cxx2cIssues.csv
+++ b/libcxx/docs/Status/Cxx2cIssues.csv
@@ -25,7 +25,7 @@
 "`LWG3809 <https://wg21.link/LWG3809>`__","Is ``std::subtract_with_carry_engine<uint16_t>`` supposed to work","2023-11 (Kona)","","",""
 "`LWG3892 <https://wg21.link/LWG3892>`__","Incorrect formatting of nested ranges and tuples","2023-11 (Kona)","|Complete|","17.0",""
 "`LWG3897 <https://wg21.link/LWG3897>`__","``inout_ptr`` will not update raw pointer to 0","2023-11 (Kona)","|Complete|","19.0",""
-"`LWG3946 <https://wg21.link/LWG3946>`__","The definition of ``const_iterator_t`` should be reworked","2023-11 (Kona)","","",""
+"`LWG3946 <https://wg21.link/LWG3946>`__","The definition of ``const_iterator_t`` should be reworked","2023-11 (Kona)","|Complete|","20.0",""
 "`LWG3947 <https://wg21.link/LWG3947>`__","Unexpected constraints on ``adjacent_transform_view::base()``","2023-11 (Kona)","","",""
 "`LWG3948 <https://wg21.link/LWG3948>`__","``possibly-const-range and as-const-pointer`` should be ``noexcept``","2023-11 (Kona)","","",""
 "`LWG3949 <https://wg21.link/LWG3949>`__","``std::atomic<bool>``'s trivial destructor dropped in C++17 spec wording","2023-11 (Kona)","","",""
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv b/libcxx/docs/Status/Cxx2cPapers.csv
index 8864b1ebe28891..fbe8b309525f35 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -42,7 +42,7 @@
 "`P2819R2 <https://wg21.link/P2819R2>`__","Add tuple protocol to complex","2023-11 (Kona)","|Complete|","19.0",""
 "`P2937R0 <https://wg21.link/P2937R0>`__","Freestanding: Remove ``strtok``","2023-11 (Kona)","","",""
 "`P2833R2 <https://wg21.link/P2833R2>`__","Freestanding Library: inout expected span","2023-11 (Kona)","","",""
-"`P2836R1 <https://wg21.link/P2836R1>`__","``std::basic_const_iterator`` should follow its underlying type's convertibility","2023-11 (Kona)","","",""
+"`P2836R1 <https://wg21.link/P2836R1>`__","``std::basic_const_iterator`` should follow its underlying type's convertibility","2023-11 (Kona)","|Complete|","20.0","This paper is applied as DR against C++23 (MSVC STL and libstdc++ have done the same). The feature macro is not yet defined, since other features from the original paper have not been completed."
 "`P2264R7 <https://wg21.link/P2264R7>`__","Make ``assert()`` macro user friendly for C and C++","2023-11 (Kona)","","",""
 "`P1673R13 <https://wg21.link/P1673R13>`__","A free function linear algebra interface based on the BLAS","2023-11 (Kona)","","",""
 "","","","","",""
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 32579272858a8e..577b7975f3eb22 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -444,6 +444,7 @@ set(files
   __iterator/bounded_iter.h
   __iterator/common_iterator.h
   __iterator/concepts.h
+  __iterator/const_iterator.h
   __iterator/counted_iterator.h
   __iterator/cpp17_iterator_concepts.h
   __iterator/data.h
@@ -639,6 +640,7 @@ set(files
   __ranges/chunk_by_view.h
   __ranges/common_view.h
   __ranges/concepts.h
+  __ranges/const_access.h
   __ranges/container_compatible_range.h
   __ranges/counted.h
   __ranges/dangling.h
diff --git a/libcxx/include/__algorithm/ranges_reverse_copy.h b/libcxx/include/__algorithm/ranges_reverse_copy.h
index e5ca5cf652dc4d..7efb6df3a8b575 100644
--- a/libcxx/include/__algorithm/ranges_reverse_copy.h
+++ b/libcxx/include/__algorithm/ranges_reverse_copy.h
@@ -34,6 +34,14 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
 
+template <ranges::bidirectional_range _Range>
+_LIBCPP_HIDE_FROM_ABI constexpr ranges::subrange<reverse_iterator<ranges::iterator_t<_Range>>,
+                                                 reverse_iterator<ranges::iterator_t<_Range>>>
+__reverse_range(_Range&& __range) {
+  auto __first = ranges::begin(__range);
+  return {std::make_reverse_iterator(ranges::next(__first, ranges::end(__range))), std::make_reverse_iterator(__first)};
+}
+
 template <class _InIter, class _OutIter>
 using reverse_copy_result = in_out_result<_InIter, _OutIter>;
 
@@ -49,7 +57,7 @@ struct __reverse_copy {
     requires indirectly_copyable<iterator_t<_Range>, _OutIter>
   _LIBCPP_HIDE_FROM_ABI constexpr reverse_copy_result<borrowed_iterator_t<_Range>, _OutIter>
   operator()(_Range&& __range, _OutIter __result) const {
-    auto __ret = ranges::copy(std::__reverse_range(__range), std::move(__result));
+    auto __ret = ranges::copy(std::ranges::__reverse_range(__range), std::move(__result));
     return {ranges::next(ranges::begin(__range), ranges::end(__range)), std::move(__ret.out)};
   }
 };
diff --git a/libcxx/include/__iterator/const_iterator.h b/libcxx/include/__iterator/const_iterator.h
new file mode 100644
index 00000000000000..4fcd76b4117dc6
--- /dev/null
+++ b/libcxx/include/__iterator/const_iterator.h
@@ -0,0 +1,351 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___ITERATOR_CONST_ITERATOR_H
+#define _LIBCPP___ITERATOR_CONST_ITERATOR_H
+
+#include <__compare/three_way_comparable.h>
+#include <__concepts/common_with.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/different_from.h>
+#include <__concepts/same_as.h>
+#include <__concepts/semiregular.h>
+#include <__concepts/totally_ordered.h>
+#include <__iterator/concepts.h>
+#include <__iterator/incrementable_traits.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__memory/addressof.h>
+#include <__memory/pointer_traits.h>
+#include <__type_traits/common_reference.h>
+#include <__type_traits/common_type.h>
+#include <__type_traits/conditional.h>
+#include <__type_traits/integral_constant.h>
+#include <__type_traits/is_reference.h>
+#include <__type_traits/is_specialization.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+template <indirectly_readable _Iter>
+using iter_const_reference_t = common_reference_t<const iter_value_t<_Iter>&&, iter_reference_t<_Iter>>;
+
+template <class _Iter>
+concept __constant_iterator = input_iterator<_Iter> && same_as<iter_const_reference_t<_Iter>, iter_reference_t<_Iter>>;
+
+template <input_iterator _Iter>
+class basic_const_iterator;
+
+template <input_iterator _Iter>
+using const_iterator = conditional_t<__constant_iterator<_Iter>, _Iter, basic_const_iterator<_Iter>>;
+
+// This doesn't use `conditional_t` to avoid instantiating const_iterator<_Sent> when _Sent is not an input_iterator.
+template <class _Sent>
+struct __const_sentinel_impl {
+  using type = _Sent;
+};
+template <class _Sent>
+  requires input_iterator<_Sent>
+struct __const_sentinel_impl<_Sent> {
+  using type = const_iterator<_Sent>;
+};
+template <semiregular _Sent>
+using const_sentinel = __const_sentinel_impl<_Sent>::type;
+
+template <class _Iter>
+concept __not_a_const_iterator = !__is_specialization_v<_Iter, basic_const_iterator>;
+
+template <indirectly_readable _Iter>
+using __iter_const_rvalue_reference_t = common_reference_t<const iter_value_t<_Iter>&&, iter_rvalue_reference_t<_Iter>>;
+
+template <class _Iter>
+struct __basic_const_iterator_concept {
+  // clang-format off
+  using iterator_concept =
+    conditional_t<contiguous_iterator<_Iter>,
+      contiguous_iterator_tag,
+    conditional_t<random_access_iterator<_Iter>,
+      random_access_iterator_tag,
+    conditional_t<bidirectional_iterator<_Iter>,
+      bidirectional_iterator_tag,
+    conditional_t<forward_iterator<_Iter>,
+      forward_iterator_tag,
+    // else
+      input_iterator_tag>>>>;
+  // clang-format on
+};
+
+template <class _Iter>
+struct __basic_const_iterator_category : __basic_const_iterator_concept<_Iter> {};
+template <forward_iterator _Iter>
+struct __basic_const_iterator_category<_Iter> : __basic_const_iterator_concept<_Iter> {
+  using iterator_category = std::iterator_traits<_Iter>::iterator_category;
+};
+
+template <input_iterator _Iter>
+class _LIBCPP_TEMPLATE_VIS basic_const_iterator : public __basic_const_iterator_category<_Iter> {
+  _Iter __current_ = _Iter();
+
+  using __reference        = iter_const_reference_t<_Iter>;
+  using __rvalue_reference = __iter_const_rvalue_reference_t<_Iter>;
+
+public:
+  using value_type      = iter_value_t<_Iter>;
+  using difference_type = iter_difference_t<_Iter>;
+
+  _LIBCPP_HIDE_FROM_ABI basic_const_iterator()
+    requires default_initializable<_Iter>
+  = default;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr basic_const_iterator(_Iter __cur) : __current_(std::move(__cur)) {}
+  template <convertible_to<_Iter> _Type>
+  _LIBCPP_HIDE_FROM_ABI constexpr basic_const_iterator(basic_const_iterator<_Type> __cur)
+      : __current_(std::move(__cur.__current_)) {}
+  template <__different_from<basic_const_iterator> _Type>
+    requires convertible_to<_Type, _Iter>
+  _LIBCPP_HIDE_FROM_ABI constexpr basic_const_iterator(_Type&& __cur) : __current_(std::forward<_Type>(__cur)) {}
+
+  _LIBCPP_HIDE_FROM_ABI constexpr const _Iter& base() const& noexcept { return __current_; }
+  _LIBCPP_HIDE_FROM_ABI constexpr _Iter base() && { return std::move(__current_); }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr __reference operator*() const { return static_cast<__reference>(*__current_); }
+  _LIBCPP_HIDE_FROM_ABI constexpr const auto* operator->() const
+    requires is_lvalue_reference_v<iter_reference_t<_Iter>> &&
+             same_as<remove_cvref_t<iter_reference_t<_Iter>>, value_type>
+  {
+    if constexpr (contiguous_iterator<_Iter>) {
+      return std::to_address(__current_);
+    } else {
+      return std::addressof(*__current_);
+    }
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr basic_const_iterator& operator++() {
+    ++__current_;
+    return *this;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr void operator++(int) { ++__current_; }
+  _LIBCPP_HIDE_FROM_ABI constexpr basic_const_iterator operator++(int)
+    requires forward_iterator<_Iter>
+  {
+    auto __tmp = *this;
+    ++__current_;
+    return __tmp;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr basic_const_iterator& operator--()
+    requires bidirectional_iterator<_Iter>
+  {
+    --__current_;
+    return *this;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr basic_const_iterator operator--(int)
+    requires bidirectional_iterator<_Iter>
+  {
+    auto __tmp = *this;
+    --__current_;
+    return __tmp;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr basic_const_iterator& operator+=(difference_type __n)
+    requires random_access_iterator<_Iter>
+  {
+    __current_ += __n;
+    return *this;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr basic_const_iterator& operator-=(difference_type __n)
+    requires random_access_iterator<_Iter>
+  {
+    __current_ -= __n;
+    return *this;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr __reference operator[](difference_type __n) const
+    requires random_access_iterator<_Iter>
+  {
+    return static_cast<__reference>(__current_[__n]);
+  }
+
+  template <sentinel_for<_Iter> _Sent>
+  _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const _Sent& __sent) const {
+    return __current_ == __sent;
+  }
+
+  template <__not_a_const_iterator _ConstIt>
+    requires __constant_iterator<_ConstIt> && convertible_to<_Iter const&, _ConstIt>
+  _LIBCPP_HIDE_FROM_ABI constexpr operator _ConstIt() const& {
+    return __current_;
+  }
+  template <__not_a_const_iterator _ConstIt>
+    requires __constant_iterator<_ConstIt> && convertible_to<_Iter, _ConstIt>
+  _LIBCPP_HIDE_FROM_ABI constexpr operator _ConstIt() && {
+    return std::move(__current_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const basic_const_iterator& __rhs) const
+    requires random_access_iterator<_Iter>
+  {
+    return __current_ < __rhs.__current_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const basic_const_iterator& __rhs) const
+    requires random_access_iterator<_Iter>
+  {
+    return __current_ > __rhs.__current_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const basic_const_iterator& __rhs) const
+    requires random_access_iterator<_Iter>
+  {
+    return __current_ <= __rhs.__current_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const basic_const_iterator& __rhs) const
+    requires random_access_iterator<_Iter>
+  {
+    return __current_ >= __rhs.__current_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(const basic_const_iterator& __rhs) const
+    requires random_access_iterator<_Iter> && three_way_comparable<_Iter>
+  {
+    return __current_ <=> __rhs.__current_;
+  }
+
+  template <__different_from<basic_const_iterator> _Iter2>
+  _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const _Iter2& __rhs) const
+    requires random_access_iterator<_Iter> && totally_ordered_with<_Iter, _Iter2>
+  {
+    return __current_ < __rhs;
+  }
+  template <__different_from<basic_const_iterator> _Iter2>
+  _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const _Iter2& __rhs) const
+    requires random_access_iterator<_Iter> && totally_ordered_with<_Iter, _Iter2>
+  {
+    return __current_ > __rhs;
+  }
+  template <__different_from<basic_const_iterator> _Iter2>
+  _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const _Iter2& __rhs) const
+    requires random_access_iterator<_Iter> && totally_ordered_with<_Iter, _Iter2>
+  {
+    return __current_ <= __rhs;
+  }
+  template <__different_from<basic_const_iterator> _Iter2>
+  _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const _Iter2& __rhs) const
+    requires random_access_iterator<_Iter> && totally_ordered_with<_Iter, _Iter2>
+  {
+    return __current_ >= __rhs;
+  }
+  template <__different_from<basic_const_iterator> _Iter2>
+  _LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(const _Iter2& __rhs) const
+    requires random_access_iterator<_Iter> && totally_ordered_with<_Iter, _Iter2> &&
+             three_way_comparable_with<_Iter, _Iter2>
+  {
+    return __current_ <=> __rhs;
+  }
+
+  template <__not_a_const_iterator _Iter2>
+  friend _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const _Iter2& __lhs, const basic_const_iterator& __rhs)
+    requires random_access_iterator<_Iter> && totally_ordered_with<_Iter, _Iter2>
+  {
+    return __lhs < __rhs.__current_;
+  }
+  template <__not_a_const_iterator _Iter2>
+  friend _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const _Iter2& __lhs, const basic_const_iterator& __rhs)
+    requires random_access_iterator<_Iter> && totally_ordered_with<_Iter, _Iter2>
+  {
+    return __lhs > __rhs.__current_;
+  }
+  template <__not_a_const_iterator _Iter2>
+  friend _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const _Iter2& __lhs, const basic_const_iterator& __rhs)
+    requires random_access_iterator<_Iter> && totally_ordered_with<_Iter, _Iter2>
+  {
+    return __lhs <= __rhs.__current_;
+  }
+  template <__not_a_const_iterator _Iter2>
+  friend _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const _Iter2& __lhs, const basic_const_iterator& __rhs)
+    requires random_access_iterator<_Iter> && totally_ordered_with<_Iter, _Iter2>
+  {
+    return __lhs >= __rhs.__current_;
+  }
+
+  friend _LIBCPP_HIDE_FROM_ABI constexpr basic_const_iterator
+  operator+(const basic_const_iterator& __it, difference_type __n)
+    requires random_access_iterator<_Iter>
+  {
+    return basic_const_iterator(__it.__current_ + __n);
+  }
+  friend _LIBCPP_HIDE_FROM_ABI constexpr basic_const_iterator
+  operator+(difference_type __n, const basic_const_iterator& __it)
+    requires random_access_iterator<_Iter>
+  {
+    return basic_const_iterator(__it.__current_ + __n);
+  }
+
+  friend _LIBCPP_HIDE_FROM_ABI constexpr basic_const_iterator
+  operator-(const basic_const_iterator& __it, difference_type __n)
+    requires random_access_iterator<_Iter>
+  {
+    return basic_const_iterator(__it.__current_ - __n);
+  }
+  template <sized_sentinel_for<_Iter> _Sent>
+  _LIBCPP_HIDE_FROM_ABI constexpr difference_type operator-(const _Sent& __rhs) const {
+    return __current_ - __rhs;
+  }
+  template <__not_a_const_iterator _Sent>
+    requires sized_sentinel_for<_Sent, _Iter>
+  friend _LIBCPP_HIDE_FROM_ABI constexpr difference_type
+  operator-(const _Sent& __lhs, const basic_const_iterator& __rhs) {
+    return __lhs - __rhs;
+  }
+
+  friend _LIBCPP_HIDE_FROM_ABI constexpr __rvalue_reference iter_move(const basic_const_iterator& __it) noexcept(
+      noexcept(static_cast<__rvalue_reference>(ranges::iter_move(__it.__current_)))) {
+    return static_cast<__rvalue_reference>(ranges::iter_move(__it.__current_));
+  }
+};
+
+template <class _Type1, common_with<_Type1> _Type2>
+  requires input_iterator<common_type_t<_Type1, _Type2>>
+struct common_type<basic_const_iterator<_Type1>, _Type2> {
+  using type = basic_const_iterator<common_type_t<_Type1, _Type2>>;
+};
+template <class _Type1, common_with<_Type1> _Type2>
+  requires input_iterator<common_type_t<_Type1, _Type2>>
+struct common_type<_Type2, basic_const_iterator<_Type1>> {
+  using type = basic_const_iterator<common_type_t<_Type1, _Type2>>;
+};
+template <class _Type1, common_with<_Type1> _Type2>
+  requires input_iterator<common_type_t<_Type1, _Type2>>
+struct common_type<basic_const_iterator<_Type1>, basic_const_iterator<_Type2>> {
+  using type = basic_const_iterator<common_type_t<_Type1, _Type2>>;
+};
+
+template <input_iterator _Iter>
+_LIBCPP_HIDE_FROM_ABI constexpr const_iterator<_Iter> make_const_iterator(_Iter __it) {
+  return __it;
+}
+template <semiregular _Sent>
+_LIBCPP_HIDE_FROM_ABI constexpr const_sentinel<_Sent> make_const_sentinel(_Sent __sent) {
+  return __sent;
+}
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ITERATOR_CONST_ITERATOR_H
diff --git a/libcxx/include/__iterator/reverse_iterator.h b/libcxx/include/__iterator/reverse_iterator.h
index 50c0f21eaa286b..823203cadf7e18 100644
--- a/libcxx/include/__iterator/reverse_iterator.h
+++ b/libcxx/include/__iterator/reverse_iterator.h
@@ -27,9 +27,6 @@
 #include <__iterator/readable_traits.h>
 #include <__iterator/segmented_iterator.h>
 #include <__memory/addressof.h>
-#include <__ranges/access.h>
-#include <__ranges/concepts.h>
-#include <__ranges/subrange.h>
 #include <__type_traits/conditional.h>
 #include <__type_traits/enable_if.h>
 #include <__type_traits/is_assignable.h>
@@ -315,16 +312,6 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Ite
 }
 #endif
 
-#if _LIBCPP_STD_VER >= 20
-template <ranges::bidirectional_range _Range>
-_LIBCPP_HIDE_FROM_ABI constexpr ranges::subrange<reverse_iterator<ranges::iterator_t<_Range>>,
-                                                 reverse_iterator<ranges::iterator_t<_Range>>>
-__reverse_range(_Range&& __range) {
-  auto __first = ranges::begin(__range);
-  return {std::make_reverse_iterator(ranges::next(__first, ranges::end(__range))), std::make_reverse_iterator(__first)};
-}
-#endif
-
 template <class _Iter, bool __b>
 struct __unwrap_iter_impl<reverse_iterator<reverse_iterator<_Iter> >, __b> {
   using _UnwrappedIter  = decltype(__unwrap_iter_impl<_Iter>::__unwrap(std::declval<_Iter>()));
diff --git a/libcxx/include/__ranges/access.h b/libcxx/include/__ranges/access.h
index c0a40c5e10178a..7955b3b2166dc2 100644
--- a/libcxx/include/__ranges/access.h
+++ b/libcxx/include/__ranges/access.h
@@ -148,61 +148,6 @@ inline constexpr auto end = __end::__fn{};
 } // namespace __cpo
 } // namespace ranges
 
-// [range.access.cbegin]
-
-namespace ranges {
-namespace __cbegin {
-struct __fn {
-  template <class _Tp>
-    requires is_lvalue_reference_v<_Tp&&>
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
-      noexcept(noexcept(ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t))))
-          -> decltype(ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t))) {
-    return ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t));
-  }
-
-  template <class _Tp>
-    requires is_rvalue_reference_v<_Tp&&>
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
-      noexcept(noexcept(ranges::begin(static_cast<const _Tp&&>(__t))))
-          -> decltype(ranges::begin(static_cast<const _Tp&&>(__t))) {
-    return ranges::begin(static_cast<const _Tp&&>(__t));
-  }
-};
-} // namespace __cbegin
-
-inline namespace __cpo {
-inline constexpr auto cbegin = __cbegin::__fn{};
-} // namespace __cpo
-} // namespace ranges
-
-// [range.access.cend]
-
-namespace ranges {
-namespace __cend {
-struct __fn {
-  template <class _Tp>
-    requires is_lvalue_reference_v<_Tp&&>
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
-      noexcept(noexcept(ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t))))
-          -> decltype(ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t))) {
-    return ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t));
-  }
-
-  template <class _Tp>
-    requires is_rvalue_reference_v<_Tp&&>
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const noexcept(
-      noexcept(ranges::end(static_cast<const _Tp&&>(__t)))) -> decltype(ranges::end(static_cast<const _Tp&&>(__t))) {
-    return ranges::end(static_cast<const _Tp&&>(__t));
-  }
-};
-} // namespace __cend
-
-inline namespace __cpo {
-inline constexpr auto cend = __cend::__fn{};
-} // namespace __cpo
-} // namespace ranges
-
 #endif // _LIBCPP_STD_VER >= 20
 
 _LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/include/__ranges/concepts.h b/libcxx/include/__ranges/concepts.h
index 674a3f359ff99c..0f1c816bfc7cdc 100644
--- a/libcxx/include/__ranges/concepts.h
+++ b/libcxx/include/__ranges/concepts.h
@@ -15,6 +15,7 @@
 #include <__concepts/same_as.h>
 #include <__config>
 #include <__iterator/concepts.h>
+#include <__iterator/const_iterator.h>
 #include <__iterator/incrementable_traits.h>
 #include <__iterator/iter_move.h>
 #include <__iterator/iterator_traits.h>
@@ -61,6 +62,8 @@ concept borrowed_range =
 template <range _Rp>
 using sentinel_t = decltype(ranges::end(std::declval<_Rp&>()));
 
+// `const_iterator_t` and `const_sentinel_t` defined in <__ranges/const_access.h>
+
 template <range _Rp>
 using range_difference_t = iter_difference_t<iterator_t<_Rp>>;
 
@@ -70,6 +73,11 @@ using range_value_t = iter_value_t<iterator_t<_Rp>>;
 template <range _Rp>
 using range_reference_t = iter_reference_t<iterator_t<_Rp>>;
 
+#  if _LIBCPP_STD_VER >= 23
+template <range _Rp>
+using range_const_reference_t = iter_const_reference_t<iterator_t<_Rp>>;
+#  endif
+
 template <range _Rp>
 using range_rvalue_reference_t = iter_rvalue_reference_t<iterator_t<_Rp>>;
 
@@ -133,6 +141,11 @@ concept viewable_range =
       (is_lvalue_reference_v<_Tp> ||
        (movable<remove_reference_t<_Tp>> && !__is_std_initializer_list<remove_cvref_t<_Tp>>))));
 
+#  if _LIBCPP_STD_VER >= 23
+template <class _Tp>
+concept constant_range = input_range<_Tp> && __constant_iterator<iterator_t<_Tp>>;
+#  endif // _LIBCPP_STD_VER >= 23
+
 } // namespace ranges
 
 #endif // _LIBCPP_STD_VER >= 20
diff --git a/libcxx/include/__ranges/const_access.h b/libcxx/include/__ranges/const_access.h
new file mode 100644
index 00000000000000..7ae530af947548
--- /dev/null
+++ b/libcxx/include/__ranges/const_access.h
@@ -0,0 +1,222 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___RANGES_CONST_ACCESS_H
+#define _LIBCPP___RANGES_CONST_ACCESS_H
+
+#include <__iterator/const_iterator.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/rbegin.h>
+#include <__ranges/rend.h>
+#include <__type_traits/is_reference.h>
+#include <__type_traits/remove_cv.h>
+#include <__type_traits/remove_reference.h>
+#include <__utility/declval.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 20
+
+// [range.const]
+#  if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template <input_range _Rp>
+_LIBCPP_HIDE_FROM_ABI constexpr auto& __possibly_const_range(_Rp& __rng) noexcept {
+  if constexpr (constant_range<const _Rp> && !constant_range<_Rp>) {
+    return const_cast<const _Rp&>(__rng);
+  } else {
+    return __rng;
+  }
+}
+} // namespace ranges
+#  endif // _LIBCPP_STD_VER >= 23
+
+// [range.access.cbegin]
+namespace ranges {
+
+template <class _Type>
+concept __const_accessible_range = (!is_rvalue_reference_v<_Type&&> || enable_borrowed_range<remove_cv_t<_Type>>);
+
+namespace __cbegin {
+struct __fn {
+#  if _LIBCPP_STD_VER >= 23
+  template <class _Rng>
+  using _UType = decltype(ranges::begin(ranges::__possibly_const_range(std::declval<_Rng&>())));
+
+  template <__const_accessible_range _Rng>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static auto
+  operator()(_Rng&& __rng) noexcept(noexcept(const_iterator<_UType<_Rng>>(
+      ranges::begin(ranges::__possibly_const_range(__rng))))) -> const_iterator<_UType<_Rng>> {
+    return const_iterator<_UType<_Rng>>(ranges::begin(ranges::__possibly_const_range(__rng)));
+  }
+#  else  // ^^^ _LIBCPP_STD_VER >= 23 / _LIBCPP_STD_VER < 23 vvv
+  template <class _Tp>
+    requires is_lvalue_reference_v<_Tp&&>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
+      noexcept(noexcept(ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t))))
+          -> decltype(ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t))) {
+    return ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t));
+  }
+
+  template <class _Tp>
+    requires is_rvalue_reference_v<_Tp&&>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
+      noexcept(noexcept(ranges::begin(static_cast<const _Tp&&>(__t))))
+          -> decltype(ranges::begin(static_cast<const _Tp&&>(__t))) {
+    return ranges::begin(static_cast<const _Tp&&>(__t));
+  }
+#  endif // ^^^ _LIBCPP_STD_VER < 23
+};
+} // namespace __cbegin
+
+inline namespace __cpo {
+inline constexpr auto cbegin = __cbegin::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+#  if _LIBCPP_STD_VER >= 23
+// [range.range]
+namespace ranges {
+template <class _Rp>
+using const_iterator_t = decltype(ranges::cbegin(std::declval<_Rp&>()));
+} // namespace ranges
+#  endif // _LIBCPP_STD_VER >= 23
+
+// [range.access.cend]
+namespace ranges {
+namespace __cend {
+struct __fn {
+#  if _LIBCPP_STD_VER >= 23
+  template <class _Rng>
+  using _UType = decltype(ranges::end(ranges::__possibly_const_range(std::declval<_Rng&>())));
+
+  template <__const_accessible_range _Rng>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static auto
+  operator()(_Rng&& __rng) noexcept(noexcept(const_sentinel<_UType<_Rng>>(
+      ranges::end(ranges::__possibly_const_range(__rng))))) -> const_sentinel<_UType<_Rng>> {
+    return const_sentinel<_UType<_Rng>>(ranges::end(ranges::__possibly_const_range(__rng)));
+  }
+#  else // ^^^ _LIBCPP_STD_VER >= 23 / _LIBCPP_STD_VER < 23 vvv
+  template <class _Tp>
+    requires is_lvalue_reference_v<_Tp&&>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
+      noexcept(noexcept(ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t))))
+          -> decltype(ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t))) {
+    return ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t));
+  }
+
+  template <class _Tp>
+    requires is_rvalue_reference_v<_Tp&&>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const noexcept(
+      noexcept(ranges::end(static_cast<const _Tp&&>(__t)))) -> decltype(ranges::end(static_cast<const _Tp&&>(__t))) {
+    return ranges::end(static_cast<const _Tp&&>(__t));
+  }
+#  endif
+};
+} // namespace __cend
+
+inline namespace __cpo {
+inline constexpr auto cend = __cend::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+// [range.range]
+namespace ranges {
+template <class _Rp>
+using const_sentinel_t = decltype(ranges::cend(std::declval<_Rp&>()));
+} // namespace ranges
+
+// [range.access.crbegin]
+namespace ranges {
+namespace __crbegin {
+struct __fn {
+#  if _LIBCPP_STD_VER >= 23
+  template <class _Rng>
+  using _UType = decltype(ranges::rbegin(ranges::__possibly_const_range(std::declval<_Rng&>())));
+
+  template <__const_accessible_range _Rng>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static auto
+  operator()(_Rng&& __rng) noexcept(noexcept(const_iterator<_UType<_Rng>>(
+      ranges::rbegin(ranges::__possibly_const_range(__rng))))) -> const_iterator<_UType<_Rng>> {
+    return const_iterator<_UType<_Rng>>(ranges::rbegin(ranges::__possibly_const_range(__rng)));
+  }
+#  else  // ^^^ _LIBCPP_STD_VER >= 23 / _LIBCPP_STD_VER < 23
+  template <class _Tp>
+    requires is_lvalue_reference_v<_Tp&&>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
+      noexcept(noexcept(ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t))))
+          -> decltype(ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t))) {
+    return ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t));
+  }
+
+  template <class _Tp>
+    requires is_rvalue_reference_v<_Tp&&>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
+      noexcept(noexcept(ranges::rbegin(static_cast<const _Tp&&>(__t))))
+          -> decltype(ranges::rbegin(static_cast<const _Tp&&>(__t))) {
+    return ranges::rbegin(static_cast<const _Tp&&>(__t));
+  }
+#  endif // ^^^ _LIBCPP_STD_VER < 23
+};
+} // namespace __crbegin
+
+inline namespace __cpo {
+inline constexpr auto crbegin = __crbegin::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+// [range.access.crend]
+namespace ranges {
+namespace __crend {
+struct __fn {
+#  if _LIBCPP_STD_VER >= 23
+  template <class _Rng>
+  using _UType = decltype(ranges::rend(ranges::__possibly_const_range(std::declval<_Rng&>())));
+
+  template <__const_accessible_range _Rng>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static auto
+  operator()(_Rng&& __rng) noexcept(noexcept(const_sentinel<_UType<_Rng>>(
+      ranges::rend(ranges::__possibly_const_range(__rng))))) -> const_sentinel<_UType<_Rng>> {
+    return const_sentinel<_UType<_Rng>>(ranges::rend(ranges::__possibly_const_range(__rng)));
+  }
+#  else  // ^^^ _LIBCPP_STD_VER >= 23 / _LIBCPP_STD_VER < 23 vvv
+  template <class _Tp>
+    requires is_lvalue_reference_v<_Tp&&>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
+      noexcept(noexcept(ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t))))
+          -> decltype(ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t))) {
+    return ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t));
+  }
+
+  template <class _Tp>
+    requires is_rvalue_reference_v<_Tp&&>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const noexcept(
+      noexcept(ranges::rend(static_cast<const _Tp&&>(__t)))) -> decltype(ranges::rend(static_cast<const _Tp&&>(__t))) {
+    return ranges::rend(static_cast<const _Tp&&>(__t));
+  }
+#  endif // ^^^ _LIBCPP_STD_VER < 23
+};
+} // namespace __crend
+
+inline namespace __cpo {
+inline constexpr auto crend = __crend::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 20
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANGES_CONST_ACCESS_H
diff --git a/libcxx/include/__ranges/rbegin.h b/libcxx/include/__ranges/rbegin.h
index 12e739e1a2b852..a6f7e2d9f1aea5 100644
--- a/libcxx/include/__ranges/rbegin.h
+++ b/libcxx/include/__ranges/rbegin.h
@@ -85,34 +85,6 @@ inline constexpr auto rbegin = __rbegin::__fn{};
 } // namespace __cpo
 } // namespace ranges
 
-// [range.access.crbegin]
-
-namespace ranges {
-namespace __crbegin {
-struct __fn {
-  template <class _Tp>
-    requires is_lvalue_reference_v<_Tp&&>
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
-      noexcept(noexcept(ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t))))
-          -> decltype(ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t))) {
-    return ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t));
-  }
-
-  template <class _Tp>
-    requires is_rvalue_reference_v<_Tp&&>
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
-      noexcept(noexcept(ranges::rbegin(static_cast<const _Tp&&>(__t))))
-          -> decltype(ranges::rbegin(static_cast<const _Tp&&>(__t))) {
-    return ranges::rbegin(static_cast<const _Tp&&>(__t));
-  }
-};
-} // namespace __crbegin
-
-inline namespace __cpo {
-inline constexpr auto crbegin = __crbegin::__fn{};
-} // namespace __cpo
-} // namespace ranges
-
 #endif // _LIBCPP_STD_VER >= 20
 
 _LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/include/__ranges/rend.h b/libcxx/include/__ranges/rend.h
index 02b4c5999a7ebb..5171cc6cf34341 100644
--- a/libcxx/include/__ranges/rend.h
+++ b/libcxx/include/__ranges/rend.h
@@ -89,33 +89,6 @@ inline constexpr auto rend = __rend::__fn{};
 } // namespace __cpo
 } // namespace ranges
 
-// [range.access.crend]
-
-namespace ranges {
-namespace __crend {
-struct __fn {
-  template <class _Tp>
-    requires is_lvalue_reference_v<_Tp&&>
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
-      noexcept(noexcept(ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t))))
-          -> decltype(ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t))) {
-    return ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t));
-  }
-
-  template <class _Tp>
-    requires is_rvalue_reference_v<_Tp&&>
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const noexcept(
-      noexcept(ranges::rend(static_cast<const _Tp&&>(__t)))) -> decltype(ranges::rend(static_cast<const _Tp&&>(__t))) {
-    return ranges::rend(static_cast<const _Tp&&>(__t));
-  }
-};
-} // namespace __crend
-
-inline namespace __cpo {
-inline constexpr auto crend = __crend::__fn{};
-} // namespace __cpo
-} // namespace ranges
-
 #endif // _LIBCPP_STD_VER >= 20
 
 _LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/include/__ranges/view_interface.h b/libcxx/include/__ranges/view_interface.h
index 3bcfbaf3a2f9ed..f825941dcba4c4 100644
--- a/libcxx/include/__ranges/view_interface.h
+++ b/libcxx/include/__ranges/view_interface.h
@@ -20,6 +20,7 @@
 #include <__memory/pointer_traits.h>
 #include <__ranges/access.h>
 #include <__ranges/concepts.h>
+#include <__ranges/const_access.h>
 #include <__ranges/empty.h>
 #include <__ranges/size.h>
 #include <__type_traits/is_class.h>
@@ -72,6 +73,27 @@ class view_interface {
     }
   }
 
+  _LIBCPP_HIDE_FROM_ABI constexpr auto cbegin()
+    requires input_range<_Derived>
+  {
+    return ranges::cbegin(__derived());
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto cbegin() const
+    requires input_range<const _Derived>
+  {
+    return ranges::cbegin(__derived());
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto cend()
+    requires input_range<_Derived>
+  {
+    return ranges::cend(__derived());
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto cend() const
+    requires input_range<const _Derived>
+  {
+    return ranges::cend(__derived());
+  }
+
   template <class _D2 = _Derived>
   _LIBCPP_HIDE_FROM_ABI constexpr explicit operator bool()
     requires requires(_D2& __t) { ranges::empty(__t); }
diff --git a/libcxx/include/iterator b/libcxx/include/iterator
index fca75f0a19ed1b..9a0c618f860cf8 100644
--- a/libcxx/include/iterator
+++ b/libcxx/include/iterator
@@ -383,6 +383,31 @@ insert_iterator<Container> inserter(Container& x, typename Container::iterator i
 template <class Container>
 constexpr insert_iterator<Container> inserter(Container& x, ranges::iterator_t<Container> i);  // since C++20
 
+template<indirectly_readable I>
+using iter_const_reference_t = see below;                                       // since C++23
+template<input_iterator I>
+using const_iterator = see below;                                               // since C++23
+template<semiregular S>
+using const_sentinel = see below;                                               // since C++23
+
+template<input_iterator Iterator>
+class basic_const_iterator;                                                     // since C++23
+
+template<class T, common_with<T> U>
+  requires input_iterator<common_type_t<T, U>>
+struct common_type<basic_const_iterator<T>, U>;                                 // since C++23
+template<class T, common_with<T> U>
+  requires input_iterator<common_type_t<T, U>>
+struct common_type<U, basic_const_iterator<T>>;                                 // since C++23
+template<class T, common_with<T> U>
+  requires input_iterator<common_type_t<T, U>>
+struct common_type<basic_const_iterator<T>, basic_const_iterator<U>>;           // since C++23
+
+template<input_iterator I>
+constexpr const_iterator<I> make_const_iterator(I it);                          // since C++23
+template<semiregular S>
+constexpr const_sentinel<S> make_const_sentinel(S s);                           // since C++23
+
 template <class Iterator>
 class move_iterator {
 public:
@@ -726,6 +751,10 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
 #  include <__iterator/unreachable_sentinel.h>
 #endif
 
+#if _LIBCPP_STD_VER >= 23
+#  include <__iterator/const_iterator.h>
+#endif
+
 #include <version>
 
 // standard-mandated includes
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index 13d0dce34d97e3..852c5b8c9fab5a 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -1401,6 +1401,7 @@ module std_private_iterator_concepts                [system] {
   export std_private_type_traits_is_reference
   export std_private_type_traits_remove_cvref
 }
+module std_private_iterator_const_iterator          [system] { header "__iterator/const_iterator.h" }
 module std_private_iterator_counted_iterator        [system] { header "__iterator/counted_iterator.h" }
 module std_private_iterator_cpp17_iterator_concepts [system] { header "__iterator/cpp17_iterator_concepts.h" }
 module std_private_iterator_data                    [system] { header "__iterator/data.h" }
@@ -1702,6 +1703,7 @@ module std_private_ranges_all                        [system] {
 module std_private_ranges_as_rvalue_view             [system] { header "__ranges/as_rvalue_view.h" }
 module std_private_ranges_chunk_by_view              [system] { header "__ranges/chunk_by_view.h" }
 module std_private_ranges_common_view                [system] { header "__ranges/common_view.h" }
+module std_private_ranges_const_access               [system] { header "__ranges/const_access.h" }
 module std_private_ranges_concepts                   [system] {
   header "__ranges/concepts.h"
   export std_private_iterator_concepts
diff --git a/libcxx/include/ranges b/libcxx/include/ranges
index fa35874265de67..5848308f089565 100644
--- a/libcxx/include/ranges
+++ b/libcxx/include/ranges
@@ -39,6 +39,10 @@ namespace std::ranges {
     using iterator_t = decltype(ranges::begin(declval<T&>()));
   template<range R>
     using sentinel_t = decltype(ranges::end(declval<R&>()));
+  template<range R>
+    using const_iterator_t = decltype(ranges::cbegin(declval<R&>()));            // since C++23
+  template<range R>
+    using const_sentinel_t = decltype(ranges::cend(declval<R&>()));              // since C++23
   template<range R>
     using range_difference_t = iter_difference_t<iterator_t<R>>;
   template<sized_range R>
@@ -47,6 +51,8 @@ namespace std::ranges {
     using range_value_t = iter_value_t<iterator_t<R>>;
   template<range R>
     using range_reference_t = iter_reference_t<iterator_t<R>>;
+  template<range R>
+    using range_const_reference_t = iter_const_reference_t<iterator_t<R>>;       // since C++23
   template<range R>
     using range_rvalue_reference_t = iter_rvalue_reference_t<iterator_t<R>>;
   template <range R>
@@ -93,6 +99,9 @@ namespace std::ranges {
   template<class T>
   concept viewable_range = see below;
 
+  template<class T>
+    concept constant_range = see below;
+
   // [range.adaptor.object], range adaptor objects
   template<class D>
     requires is_class_v<D> && same_as<D, remove_cv_t<D>>
@@ -387,6 +396,7 @@ namespace std {
 #  include <__ranges/all.h>
 #  include <__ranges/common_view.h>
 #  include <__ranges/concepts.h>
+#  include <__ranges/const_access.h>
 #  include <__ranges/counted.h>
 #  include <__ranges/dangling.h>
 #  include <__ranges/data.h>
diff --git a/libcxx/include/version b/libcxx/include/version
index dc1d3fd268ce83..6c4d45656b20f4 100644
--- a/libcxx/include/version
+++ b/libcxx/include/version
@@ -185,7 +185,7 @@ __cpp_lib_quoted_string_io                              201304L <iomanip>
 __cpp_lib_ranges                                        202406L <algorithm> <functional> <iterator>
                                                                 <memory> <ranges>
                                                         202110L // C++20
-__cpp_lib_ranges_as_const                               202207L <ranges>
+__cpp_lib_ranges_as_const                               202311L <ranges>
 __cpp_lib_ranges_as_rvalue                              202207L <ranges>
 __cpp_lib_ranges_chunk                                  202202L <ranges>
 __cpp_lib_ranges_chunk_by                               202202L <ranges>
@@ -483,7 +483,7 @@ __cpp_lib_void_t                                        201411L <type_traits>
 # define __cpp_lib_print                                202207L
 # undef  __cpp_lib_ranges
 # define __cpp_lib_ranges                               202406L
-// # define __cpp_lib_ranges_as_const                      202207L
+// # define __cpp_lib_ranges_as_const                      202311L
 # define __cpp_lib_ranges_as_rvalue                     202207L
 // # define __cpp_lib_ranges_chunk                         202202L
 # define __cpp_lib_ranges_chunk_by                      202202L
diff --git a/libcxx/modules/std/iterator.inc b/libcxx/modules/std/iterator.inc
index 10c63d74e6e05e..5278ceaf2785b6 100644
--- a/libcxx/modules/std/iterator.inc
+++ b/libcxx/modules/std/iterator.inc
@@ -182,18 +182,21 @@ export namespace std {
   using std::insert_iterator;
   using std::inserter;
 
+#if _LIBCPP_STD_VER >= 23
   // [const.iterators], constant iterators and sentinels
   // [const.iterators.alias], alias templates
-  //  using std::const_iterator;
-  //  using std::const_sentinel;
-  //  using std::iter_const_reference_t;
+  using std::const_iterator;
+  using std::const_sentinel;
+  using std::iter_const_reference_t;
 
   // [const.iterators.iterator], class template basic_const_iterator
-  //  using std::basic_const_iterator;
+  using std::basic_const_iterator;
 
-  // using std::common_type;
+  using std::common_type;
 
-  //  using std::make_const_iterator;
+  using std::make_const_iterator;
+  using std::make_const_sentinel;
+#endif
 
   // [move.iterators], move iterators and sentinels
   using std::move_iterator;
diff --git a/libcxx/modules/std/ranges.inc b/libcxx/modules/std/ranges.inc
index f71efe948ede10..e111d818a3ae00 100644
--- a/libcxx/modules/std/ranges.inc
+++ b/libcxx/modules/std/ranges.inc
@@ -34,10 +34,14 @@ export namespace std {
 
     using std::ranges::borrowed_range;
 
-    // using std::ranges::const_iterator_t;
-    // using std::ranges::const_sentinel_t;
+#if _LIBCPP_STD_VER >= 23
+    using std::ranges::const_iterator_t;
+    using std::ranges::const_sentinel_t;
+#endif
     using std::ranges::iterator_t;
-    // using std::ranges::range_const_reference_t;
+#if _LIBCPP_STD_VER >= 23
+    using std::ranges::range_const_reference_t;
+#endif
     using std::ranges::range_common_reference_t;
     using std::ranges::range_difference_t;
     using std::ranges::range_reference_t;
@@ -58,7 +62,9 @@ export namespace std {
     // [range.refinements], other range refinements
     using std::ranges::bidirectional_range;
     using std::ranges::common_range;
-    // using std::ranges::constant_range;
+#if _LIBCPP_STD_VER >= 23
+    using std::ranges::constant_range;
+#endif
     using std::ranges::contiguous_range;
     using std::ranges::forward_range;
     using std::ranges::input_range;
diff --git a/libcxx/test/std/iterators/const.iterators/alias.pass.cpp b/libcxx/test/std/iterators/const.iterators/alias.pass.cpp
new file mode 100644
index 00000000000000..10c0665764cc86
--- /dev/null
+++ b/libcxx/test/std/iterators/const.iterators/alias.pass.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// std::const_iterator
+
+#include <iterator>
+#include <list>
+#include <ranges>
+#include "test_macros.h"
+
+ASSERT_SAME_TYPE(std::const_iterator<int*>, std::basic_const_iterator<int*>);
+ASSERT_SAME_TYPE(std::const_iterator<const int*>, const int*);
+ASSERT_SAME_TYPE(std::const_sentinel<int*>, std::basic_const_iterator<int*>);
+ASSERT_SAME_TYPE(std::const_sentinel<const int*>, const int*);
+ASSERT_SAME_TYPE(std::const_sentinel<std::default_sentinel_t>, std::default_sentinel_t);
+
+using list_iterator       = std::list<int>::iterator;
+using list_const_iterator = std::list<int>::const_iterator;
+
+ASSERT_SAME_TYPE(std::const_iterator<list_iterator>, std::basic_const_iterator<list_iterator>);
+ASSERT_SAME_TYPE(std::const_iterator<list_const_iterator>, list_const_iterator);
+ASSERT_SAME_TYPE(std::const_sentinel<list_iterator>, std::basic_const_iterator<list_iterator>);
+ASSERT_SAME_TYPE(std::const_sentinel<list_const_iterator>, list_const_iterator);
+
+int main() { return 0; }
diff --git a/libcxx/test/std/iterators/const.iterators/iterator.pass.cpp b/libcxx/test/std/iterators/const.iterators/iterator.pass.cpp
new file mode 100644
index 00000000000000..9163976deb8f12
--- /dev/null
+++ b/libcxx/test/std/iterators/const.iterators/iterator.pass.cpp
@@ -0,0 +1,139 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// std::basic_const_iterator
+
+#include <iterator>
+#include <list>
+#include <ranges>
+#include <vector>
+#include "test_macros.h"
+#include "test_iterators.h"
+#include "type_algorithms.h"
+
+template <class T>
+concept has_iterator_category = requires { typename T::iterator_category; };
+
+template <class It>
+constexpr bool check_category_and_concept() {
+  using ConstIt = std::basic_const_iterator<It>;
+
+  if constexpr (std::contiguous_iterator<It>) {
+    ASSERT_SAME_TYPE(typename ConstIt::iterator_concept, std::contiguous_iterator_tag);
+    static_assert(std::contiguous_iterator<ConstIt>);
+  } else if constexpr (std::random_access_iterator<It>) {
+    ASSERT_SAME_TYPE(typename ConstIt::iterator_concept, std::random_access_iterator_tag);
+    static_assert(!std::contiguous_iterator<ConstIt>);
+    static_assert(std::random_access_iterator<ConstIt>);
+  } else if constexpr (std::bidirectional_iterator<It>) {
+    ASSERT_SAME_TYPE(typename ConstIt::iterator_concept, std::bidirectional_iterator_tag);
+    static_assert(!std::random_access_iterator<ConstIt>);
+    static_assert(std::bidirectional_iterator<ConstIt>);
+  } else if constexpr (std::forward_iterator<It>) {
+    ASSERT_SAME_TYPE(typename ConstIt::iterator_concept, std::forward_iterator_tag);
+    static_assert(!std::bidirectional_iterator<ConstIt>);
+    static_assert(std::forward_iterator<ConstIt>);
+  } else {
+    ASSERT_SAME_TYPE(typename ConstIt::iterator_concept, std::input_iterator_tag);
+    static_assert(!std::forward_iterator<ConstIt>);
+    static_assert(std::input_iterator<ConstIt>);
+  }
+
+  if constexpr (std::forward_iterator<It>) {
+    ASSERT_SAME_TYPE(typename ConstIt::iterator_category, typename std::iterator_traits<It>::iterator_category);
+  } else {
+    static_assert(!has_iterator_category<ConstIt>);
+  }
+
+  return true;
+}
+
+constexpr bool test_p2836r1() {
+  auto f = [](std::vector<int>::const_iterator) {};
+
+  auto v = std::vector<int>();
+  {
+    auto i1 = std::ranges::cbegin(v);
+    f(i1);
+  }
+
+  auto t = v | std::views::take_while([](int const x) { return x < 100; });
+  {
+    auto i2 = std::ranges::cbegin(t);
+    f(i2);
+  }
+
+  return true;
+}
+
+constexpr bool test_basic_operations() {
+  struct S {
+    int x;
+  };
+  S arr[10]                           = {};
+  std::basic_const_iterator<S*> first = arr;
+  std::basic_const_iterator<S*> last  = arr + 10;
+
+  for (auto it = first; it != last; ++it) {
+    (void)*it;
+    (void)it->x;
+    (void)iter_move(it);
+  }
+  static_assert(!std::is_invocable_v<decltype(std::ranges::iter_swap), decltype(first), decltype(first)>);
+
+  assert(++first == arr + 1);
+  assert(--first == arr + 0);
+  assert(first++ == arr + 0);
+  assert(first-- == arr + 1);
+
+  assert(first + 3 == arr + 3);
+  assert(last - 1 == arr + 9);
+
+  first += 3;
+  assert(first == arr + 3);
+  first -= 2;
+  assert(first == arr + 1);
+  --first;
+
+  assert(first < last);
+  assert(last > first);
+  assert(first <= last);
+  assert(last >= first);
+
+  assert(first < arr + 1);
+  assert(arr + 1 > first);
+  assert(first <= arr + 1);
+  assert(arr + 1 >= first);
+
+  assert((first <=> last) < 0);
+  assert((first <=> arr + 1) < 0);
+  assert((arr + 1 <=> first) > 0);
+
+  return true;
+}
+
+int main() {
+  types::for_each(types::cpp20_input_iterator_list<int*>{}, []<class It>() {
+    using ConstIt = std::basic_const_iterator<It>;
+    ASSERT_SAME_TYPE(typename ConstIt::value_type, int);
+    static_assert(check_category_and_concept<It>());
+
+    ASSERT_SAME_TYPE(std::iter_reference_t<ConstIt>, const int&);
+    ASSERT_SAME_TYPE(std::iter_rvalue_reference_t<ConstIt>, const int&&);
+  });
+
+  test_p2836r1();
+  static_assert(test_p2836r1());
+
+  test_basic_operations();
+  static_assert(test_basic_operations());
+
+  return 0;
+}
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/ranges.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/ranges.version.compile.pass.cpp
index 8493505ef0236d..e4289071d0ca89 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/ranges.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/ranges.version.compile.pass.cpp
@@ -19,7 +19,7 @@
     __cpp_lib_default_template_type_for_algorithm_values    202403L [C++26]
     __cpp_lib_ranges                                        202110L [C++20]
                                                             202406L [C++23]
-    __cpp_lib_ranges_as_const                               202207L [C++23]
+    __cpp_lib_ranges_as_const                               202311L [C++23]
     __cpp_lib_ranges_as_rvalue                              202207L [C++23]
     __cpp_lib_ranges_chunk                                  202202L [C++23]
     __cpp_lib_ranges_chunk_by                               202202L [C++23]
@@ -254,8 +254,8 @@
 #   ifndef __cpp_lib_ranges_as_const
 #     error "__cpp_lib_ranges_as_const should be defined in c++23"
 #   endif
-#   if __cpp_lib_ranges_as_const != 202207L
-#     error "__cpp_lib_ranges_as_const should have the value 202207L in c++23"
+#   if __cpp_lib_ranges_as_const != 202311L
+#     error "__cpp_lib_ranges_as_const should have the value 202311L in c++23"
 #   endif
 # else // _LIBCPP_VERSION
 #   ifdef __cpp_lib_ranges_as_const
@@ -373,8 +373,8 @@
 #   ifndef __cpp_lib_ranges_as_const
 #     error "__cpp_lib_ranges_as_const should be defined in c++26"
 #   endif
-#   if __cpp_lib_ranges_as_const != 202207L
-#     error "__cpp_lib_ranges_as_const should have the value 202207L in c++26"
+#   if __cpp_lib_ranges_as_const != 202311L
+#     error "__cpp_lib_ranges_as_const should have the value 202311L in c++26"
 #   endif
 # else // _LIBCPP_VERSION
 #   ifdef __cpp_lib_ranges_as_const
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
index a022c90e166c8d..7afc1300f16e72 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
@@ -168,7 +168,7 @@
     __cpp_lib_quoted_string_io                              201304L [C++14]
     __cpp_lib_ranges                                        202110L [C++20]
                                                             202406L [C++23]
-    __cpp_lib_ranges_as_const                               202207L [C++23]
+    __cpp_lib_ranges_as_const                               202311L [C++23]
     __cpp_lib_ranges_as_rvalue                              202207L [C++23]
     __cpp_lib_ranges_chunk                                  202202L [C++23]
     __cpp_lib_ranges_chunk_by                               202202L [C++23]
@@ -5628,8 +5628,8 @@
 #   ifndef __cpp_lib_ranges_as_const
 #     error "__cpp_lib_ranges_as_const should be defined in c++23"
 #   endif
-#   if __cpp_lib_ranges_as_const != 202207L
-#     error "__cpp_lib_ranges_as_const should have the value 202207L in c++23"
+#   if __cpp_lib_ranges_as_const != 202311L
+#     error "__cpp_lib_ranges_as_const should have the value 202311L in c++23"
 #   endif
 # else // _LIBCPP_VERSION
 #   ifdef __cpp_lib_ranges_as_const
@@ -7479,8 +7479,8 @@
 #   ifndef __cpp_lib_ranges_as_const
 #     error "__cpp_lib_ranges_as_const should be defined in c++26"
 #   endif
-#   if __cpp_lib_ranges_as_const != 202207L
-#     error "__cpp_lib_ranges_as_const should have the value 202207L in c++26"
+#   if __cpp_lib_ranges_as_const != 202311L
+#     error "__cpp_lib_ranges_as_const should have the value 202311L in c++26"
 #   endif
 # else // _LIBCPP_VERSION
 #   ifdef __cpp_lib_ranges_as_const
diff --git a/libcxx/test/std/ranges/range.access/begin.pass.cpp b/libcxx/test/std/ranges/range.access/begin.pass.cpp
index 5ca3d59abb1407..7f2357b319a8a0 100644
--- a/libcxx/test/std/ranges/range.access/begin.pass.cpp
+++ b/libcxx/test/std/ranges/range.access/begin.pass.cpp
@@ -9,7 +9,7 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 
 // std::ranges::begin
-// std::ranges::cbegin
+// std::ranges::cbegin // until C++23
 
 #include <ranges>
 
@@ -19,7 +19,9 @@
 #include "test_iterators.h"
 
 using RangeBeginT = decltype(std::ranges::begin);
+#if TEST_STD_VER < 23
 using RangeCBeginT = decltype(std::ranges::cbegin);
+#endif // TEST_STD_VER < 23
 
 static int globalBuff[8];
 
@@ -27,33 +29,43 @@ static_assert(!std::is_invocable_v<RangeBeginT, int (&&)[10]>);
 static_assert( std::is_invocable_v<RangeBeginT, int (&)[10]>);
 static_assert(!std::is_invocable_v<RangeBeginT, int (&&)[]>);
 static_assert( std::is_invocable_v<RangeBeginT, int (&)[]>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCBeginT, int (&&)[10]>);
 static_assert( std::is_invocable_v<RangeCBeginT, int (&)[10]>);
 static_assert(!std::is_invocable_v<RangeCBeginT, int (&&)[]>);
 static_assert( std::is_invocable_v<RangeCBeginT, int (&)[]>);
+#endif // TEST_STD_VER < 23
 
 struct Incomplete;
 static_assert(!std::is_invocable_v<RangeBeginT, Incomplete(&&)[]>);
 static_assert(!std::is_invocable_v<RangeBeginT, const Incomplete(&&)[]>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCBeginT, Incomplete(&&)[]>);
 static_assert(!std::is_invocable_v<RangeCBeginT, const Incomplete(&&)[]>);
+#endif // TEST_STD_VER < 23
 
 static_assert(!std::is_invocable_v<RangeBeginT, Incomplete(&&)[10]>);
 static_assert(!std::is_invocable_v<RangeBeginT, const Incomplete(&&)[10]>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCBeginT, Incomplete(&&)[10]>);
 static_assert(!std::is_invocable_v<RangeCBeginT, const Incomplete(&&)[10]>);
+#endif // TEST_STD_VER < 23
 
 // This case is IFNDR; we handle it SFINAE-friendly.
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeBeginT, Incomplete(&)[]>);
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeBeginT, const Incomplete(&)[]>);
+#if TEST_STD_VER < 23
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCBeginT, Incomplete(&)[]>);
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCBeginT, const Incomplete(&)[]>);
+#endif // TEST_STD_VER < 23
 
 // This case is IFNDR; we handle it SFINAE-friendly.
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeBeginT, Incomplete(&)[10]>);
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeBeginT, const Incomplete(&)[10]>);
+#if TEST_STD_VER < 23
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCBeginT, Incomplete(&)[10]>);
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCBeginT, const Incomplete(&)[10]>);
+#endif // TEST_STD_VER < 23
 
 struct BeginMember {
   int x;
@@ -65,45 +77,48 @@ static_assert( std::is_invocable_v<RangeBeginT, BeginMember &>);
 static_assert(!std::is_invocable_v<RangeBeginT, BeginMember &&>);
 static_assert( std::is_invocable_v<RangeBeginT, BeginMember const&>);
 static_assert(!std::is_invocable_v<RangeBeginT, BeginMember const&&>);
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCBeginT, BeginMember &>);
 static_assert(!std::is_invocable_v<RangeCBeginT, BeginMember &&>);
 static_assert( std::is_invocable_v<RangeCBeginT, BeginMember const&>);
 static_assert(!std::is_invocable_v<RangeCBeginT, BeginMember const&&>);
+#endif // TEST_STD_VER < 23
 
 constexpr bool testReturnTypes() {
-  {
-    int *x[2];
-    ASSERT_SAME_TYPE(decltype(std::ranges::begin(x)), int**);
-    ASSERT_SAME_TYPE(decltype(std::ranges::cbegin(x)), int* const*);
-  }
-  {
-    int x[2][2];
-    ASSERT_SAME_TYPE(decltype(std::ranges::begin(x)), int(*)[2]);
-    ASSERT_SAME_TYPE(decltype(std::ranges::cbegin(x)), const int(*)[2]);
-  }
-  {
-    struct Different {
-      char*& begin();
-      short*& begin() const;
-    } x;
-    ASSERT_SAME_TYPE(decltype(std::ranges::begin(x)), char*);
-    ASSERT_SAME_TYPE(decltype(std::ranges::cbegin(x)), short*);
-  }
+  int* a[2];
+  int b[2][2];
+  struct Different {
+    char*& begin();
+    short*& begin() const;
+  } c;
+
+  ASSERT_SAME_TYPE(decltype(std::ranges::begin(a)), int**);
+  ASSERT_SAME_TYPE(decltype(std::ranges::begin(b)), int(*)[2]);
+  ASSERT_SAME_TYPE(decltype(std::ranges::begin(c)), char*);
+
+#if TEST_STD_VER < 23
+  ASSERT_SAME_TYPE(decltype(std::ranges::cbegin(a)), int* const*);
+  ASSERT_SAME_TYPE(decltype(std::ranges::cbegin(b)), const int(*)[2]);
+  ASSERT_SAME_TYPE(decltype(std::ranges::cbegin(c)), short*);
+#endif // TEST_STD_VER < 23
+
   return true;
 }
 
 constexpr bool testArray() {
   int a[2];
-  assert(std::ranges::begin(a) == a);
-  assert(std::ranges::cbegin(a) == a);
-
   int b[2][2];
-  assert(std::ranges::begin(b) == b);
-  assert(std::ranges::cbegin(b) == b);
-
   BeginMember c[2];
+
+  assert(std::ranges::begin(a) == a);
+  assert(std::ranges::begin(b) == b);
   assert(std::ranges::begin(c) == c);
+
+#if TEST_STD_VER < 23
+  assert(std::ranges::cbegin(a) == a);
+  assert(std::ranges::cbegin(b) == b);
   assert(std::ranges::cbegin(c) == c);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
@@ -136,8 +151,10 @@ struct NonConstBeginMember {
 };
 static_assert( std::is_invocable_v<RangeBeginT,  NonConstBeginMember &>);
 static_assert(!std::is_invocable_v<RangeBeginT,  NonConstBeginMember const&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCBeginT, NonConstBeginMember &>);
 static_assert(!std::is_invocable_v<RangeCBeginT, NonConstBeginMember const&>);
+#endif // TEST_STD_VER < 23
 
 struct EnabledBorrowingBeginMember {
   constexpr int *begin() const { return &globalBuff[0]; }
@@ -159,28 +176,28 @@ struct EmptyPtrBeginMember {
 
 constexpr bool testBeginMember() {
   BeginMember a;
+  NonConstBeginMember b;
+  EnabledBorrowingBeginMember c;
+  BeginMemberFunction d;
+  EmptyPtrBeginMember e;
+
   assert(std::ranges::begin(a) == &a.x);
-  assert(std::ranges::cbegin(a) == &a.x);
   static_assert(!std::is_invocable_v<RangeBeginT, BeginMember&&>);
-  static_assert(!std::is_invocable_v<RangeCBeginT, BeginMember&&>);
-
-  NonConstBeginMember b;
   assert(std::ranges::begin(b) == &b.x);
-  static_assert(!std::is_invocable_v<RangeCBeginT, NonConstBeginMember&>);
-
-  EnabledBorrowingBeginMember c;
   assert(std::ranges::begin(c) == &globalBuff[0]);
-  assert(std::ranges::cbegin(c) == &globalBuff[0]);
   assert(std::ranges::begin(std::move(c)) == &globalBuff[0]);
-  assert(std::ranges::cbegin(std::move(c)) == &globalBuff[0]);
-
-  BeginMemberFunction d;
   assert(std::ranges::begin(d) == &d.x);
-  assert(std::ranges::cbegin(d) == &d.x);
-
-  EmptyPtrBeginMember e;
   assert(std::ranges::begin(e) == &e.x);
+
+#if TEST_STD_VER < 23
+  assert(std::ranges::cbegin(a) == &a.x);
+  static_assert(!std::is_invocable_v<RangeCBeginT, BeginMember&&>);
+  static_assert(!std::is_invocable_v<RangeCBeginT, NonConstBeginMember&>);
+  assert(std::ranges::cbegin(c) == &globalBuff[0]);
+  assert(std::ranges::cbegin(std::move(c)) == &globalBuff[0]);
+  assert(std::ranges::cbegin(d) == &d.x);
   assert(std::ranges::cbegin(e) == &e.x);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
@@ -193,8 +210,10 @@ struct BeginFunction {
 static_assert( std::is_invocable_v<RangeBeginT,  BeginFunction const&>);
 static_assert(!std::is_invocable_v<RangeBeginT,  BeginFunction &&>);
 static_assert(std::is_invocable_v<RangeBeginT, BeginFunction&>); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCBeginT, BeginFunction const&>);
 static_assert( std::is_invocable_v<RangeCBeginT, BeginFunction &>);
+#endif // TEST_STD_VER < 23
 
 struct BeginFunctionReturnsInt {
   friend int begin(BeginFunctionReturnsInt const&);
@@ -215,7 +234,9 @@ static_assert(!std::is_invocable_v<RangeBeginT, BeginFunctionReturnsPtrConvertib
 struct BeginFunctionByValue {
   friend constexpr int *begin(BeginFunctionByValue) { return &globalBuff[1]; }
 };
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCBeginT, BeginFunctionByValue>);
+#endif // TEST_STD_VER < 23
 
 struct BeginFunctionEnabledBorrowing {
   friend constexpr int *begin(BeginFunctionEnabledBorrowing) { return &globalBuff[2]; }
@@ -245,85 +266,96 @@ struct BeginFunctionWithPrivateBeginMember {
 constexpr bool testBeginFunction() {
   BeginFunction a{};
   const BeginFunction aa{};
-  assert(std::ranges::begin(a) == &a.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
-  assert(std::ranges::cbegin(a) == &a.x);
-  assert(std::ranges::begin(aa) == &aa.x);
-  assert(std::ranges::cbegin(aa) == &aa.x);
-
   BeginFunctionByValue b{};
   const BeginFunctionByValue bb{};
-  assert(std::ranges::begin(b) == &globalBuff[1]);
-  assert(std::ranges::cbegin(b) == &globalBuff[1]);
-  assert(std::ranges::begin(bb) == &globalBuff[1]);
-  assert(std::ranges::cbegin(bb) == &globalBuff[1]);
-
   BeginFunctionEnabledBorrowing c{};
   const BeginFunctionEnabledBorrowing cc{};
-  assert(std::ranges::begin(std::move(c)) == &globalBuff[2]);
-  assert(std::ranges::cbegin(std::move(c)) == &globalBuff[2]);
-  assert(std::ranges::begin(std::move(cc)) == &globalBuff[2]);
-  assert(std::ranges::cbegin(std::move(cc)) == &globalBuff[2]);
-
   BeginFunctionReturnsEmptyPtr d{};
   const BeginFunctionReturnsEmptyPtr dd{};
-  assert(std::ranges::begin(d) == &d.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
-  assert(std::ranges::cbegin(d) == &d.x);
-  assert(std::ranges::begin(dd) == &dd.x);
-  assert(std::ranges::cbegin(dd) == &dd.x);
-
   BeginFunctionWithDataMember e{};
   const BeginFunctionWithDataMember ee{};
+  BeginFunctionWithPrivateBeginMember f{};
+  const BeginFunctionWithPrivateBeginMember ff{};
+
+  assert(std::ranges::begin(a) == &a.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+  assert(std::ranges::begin(aa) == &aa.x);
+  assert(std::ranges::begin(b) == &globalBuff[1]);
+  assert(std::ranges::begin(bb) == &globalBuff[1]);
+  assert(std::ranges::begin(std::move(c)) == &globalBuff[2]);
+  assert(std::ranges::begin(std::move(cc)) == &globalBuff[2]);
+  assert(std::ranges::begin(d) == &d.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+  assert(std::ranges::begin(dd) == &dd.x);
   assert(std::ranges::begin(e) == &e.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
   assert(std::ranges::begin(ee) == &ee.x);
+  assert(std::ranges::begin(f) == &f.y); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+  assert(std::ranges::begin(ff) == &ff.y);
+
+#if TEST_STD_VER < 23
+  assert(std::ranges::cbegin(a) == &a.x);
+  assert(std::ranges::cbegin(aa) == &aa.x);
+  assert(std::ranges::cbegin(b) == &globalBuff[1]);
+  assert(std::ranges::cbegin(bb) == &globalBuff[1]);
+  assert(std::ranges::cbegin(std::move(c)) == &globalBuff[2]);
+  assert(std::ranges::cbegin(std::move(cc)) == &globalBuff[2]);
+  assert(std::ranges::cbegin(d) == &d.x);
+  assert(std::ranges::cbegin(dd) == &dd.x);
   assert(std::ranges::cbegin(e) == &e.x);
   assert(std::ranges::cbegin(ee) == &ee.x);
-
-  BeginFunctionWithPrivateBeginMember f{};
-  const BeginFunctionWithPrivateBeginMember ff{};
-  assert(std::ranges::begin(f) == &f.y); // Ill-formed before P2602R2 Poison Pills are Too Toxic
   assert(std::ranges::cbegin(f) == &f.y);
-  assert(std::ranges::begin(ff) == &ff.y);
   assert(std::ranges::cbegin(ff) == &ff.y);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
 
 
 ASSERT_NOEXCEPT(std::ranges::begin(std::declval<int (&)[10]>()));
+#if TEST_STD_VER < 23
 ASSERT_NOEXCEPT(std::ranges::cbegin(std::declval<int (&)[10]>()));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowMemberBegin {
   ThrowingIterator<int> begin() const noexcept; // auto(t.begin()) doesn't throw
 } ntmb;
 static_assert(noexcept(std::ranges::begin(ntmb)));
+#if TEST_STD_VER < 23
 static_assert(noexcept(std::ranges::cbegin(ntmb)));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowADLBegin {
   friend ThrowingIterator<int> begin(NoThrowADLBegin&) noexcept;  // auto(begin(t)) doesn't throw
   friend ThrowingIterator<int> begin(const NoThrowADLBegin&) noexcept;
 } ntab;
 static_assert(noexcept(std::ranges::begin(ntab)));
+#if TEST_STD_VER < 23
 static_assert(noexcept(std::ranges::cbegin(ntab)));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowMemberBeginReturnsRef {
   ThrowingIterator<int>& begin() const noexcept; // auto(t.begin()) may throw
 } ntmbrr;
 static_assert(!noexcept(std::ranges::begin(ntmbrr)));
+#if TEST_STD_VER < 23
 static_assert(!noexcept(std::ranges::cbegin(ntmbrr)));
+#endif // TEST_STD_VER < 23
 
 struct BeginReturnsArrayRef {
     auto begin() const noexcept -> int(&)[10];
 } brar;
 static_assert(noexcept(std::ranges::begin(brar)));
+#if TEST_STD_VER < 23
 static_assert(noexcept(std::ranges::cbegin(brar)));
+#endif // TEST_STD_VER < 23
 
 // Test ADL-proofing.
 struct Incomplete;
 template<class T> struct Holder { T t; };
 static_assert(!std::is_invocable_v<RangeBeginT, Holder<Incomplete>*>);
 static_assert(!std::is_invocable_v<RangeBeginT, Holder<Incomplete>*&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCBeginT, Holder<Incomplete>*>);
 static_assert(!std::is_invocable_v<RangeCBeginT, Holder<Incomplete>*&>);
+#endif // TEST_STD_VER < 23
 
 int main(int, char**) {
   static_assert(testReturnTypes());
diff --git a/libcxx/test/std/ranges/range.access/cbegin.pass.cpp b/libcxx/test/std/ranges/range.access/cbegin.pass.cpp
new file mode 100644
index 00000000000000..a2da7cdf3b6d39
--- /dev/null
+++ b/libcxx/test/std/ranges/range.access/cbegin.pass.cpp
@@ -0,0 +1,207 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// std::ranges::cbegin
+// std::ranges::crbegin
+
+#include <ranges>
+
+#include <cassert>
+#include <utility>
+#include "almost_satisfies_types.h"
+#include "test_macros.h"
+#include "test_iterators.h"
+
+using RangeCBeginT  = decltype(std::ranges::cbegin);
+using RangeCRBeginT = decltype(std::ranges::crbegin);
+
+static_assert(!std::is_invocable_v<RangeCBeginT, int (&&)[10]>);
+static_assert(std::is_invocable_v<RangeCBeginT, int (&)[10]>);
+static_assert(!std::is_invocable_v<RangeCBeginT, int (&&)[]>);
+static_assert(!std::is_invocable_v<RangeCBeginT, int (&)[]>);
+static_assert(!std::is_invocable_v<RangeCRBeginT, int (&&)[10]>);
+static_assert(std::is_invocable_v<RangeCRBeginT, int (&)[10]>);
+static_assert(!std::is_invocable_v<RangeCRBeginT, int (&&)[]>);
+static_assert(!std::is_invocable_v<RangeCRBeginT, int (&)[]>);
+
+static_assert(!std::is_invocable_v<RangeCBeginT, InputRangeNotDerivedFrom>);
+static_assert(!std::is_invocable_v<RangeCBeginT, InputRangeNotIndirectlyReadable>);
+static_assert(!std::is_invocable_v<RangeCBeginT, InputRangeNotInputOrOutputIterator>);
+static_assert(!std::is_invocable_v<RangeCBeginT, InputRangeNotSentinelSemiregular>);
+static_assert(!std::is_invocable_v<RangeCBeginT, InputRangeNotSentinelEqualityComparableWith>);
+
+static_assert(!std::is_invocable_v<RangeCRBeginT, BidirectionalRangeNotDerivedFrom>);
+static_assert(!std::is_invocable_v<RangeCRBeginT, BidirectionalRangeNotSentinelSemiregular>);
+static_assert(!std::is_invocable_v<RangeCRBeginT, BidirectionalRangeNotSentinelWeaklyEqualityComparableWith>);
+static_assert(!std::is_invocable_v<RangeCRBeginT, BidirectionalRangeNotDecrementable>);
+
+struct Incomplete;
+
+static_assert(!std::is_invocable_v<RangeCBeginT, Incomplete (&&)[]>);
+static_assert(!std::is_invocable_v<RangeCBeginT, const Incomplete (&&)[]>);
+static_assert(!std::is_invocable_v<RangeCBeginT, Incomplete (&&)[10]>);
+static_assert(!std::is_invocable_v<RangeCBeginT, const Incomplete (&&)[10]>);
+
+static_assert(!std::is_invocable_v<RangeCRBeginT, Incomplete (&&)[]>);
+static_assert(!std::is_invocable_v<RangeCRBeginT, const Incomplete (&&)[]>);
+static_assert(!std::is_invocable_v<RangeCRBeginT, Incomplete (&&)[10]>);
+static_assert(!std::is_invocable_v<RangeCRBeginT, const Incomplete (&&)[10]>);
+
+// This case is IFNDR; we handle it SFINAE-friendly.
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCBeginT, Incomplete (&)[]>);
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCBeginT, const Incomplete (&)[]>);
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCRBeginT, Incomplete (&)[]>);
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCRBeginT, const Incomplete (&)[]>);
+
+// This case is IFNDR; we handle it SFINAE-friendly.
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCBeginT, Incomplete (&)[10]>);
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCBeginT, const Incomplete (&)[10]>);
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCRBeginT, Incomplete (&)[10]>);
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCRBeginT, const Incomplete (&)[10]>);
+
+struct NonborrowingRange {
+  int x;
+  constexpr const int* begin() const { return &x; }
+  constexpr const int* rbegin() const { return &x; }
+  constexpr const int* end() const { return &x; }
+  constexpr const int* rend() const { return &x; }
+};
+
+// Ensure that we can't call with rvalues with borrowing disabled.
+static_assert(std::is_invocable_v<RangeCBeginT, NonborrowingRange&>);
+static_assert(!std::is_invocable_v<RangeCBeginT, NonborrowingRange&&>);
+static_assert(std::is_invocable_v<RangeCBeginT, NonborrowingRange const&>);
+static_assert(!std::is_invocable_v<RangeCBeginT, NonborrowingRange const&&>);
+static_assert(std::is_invocable_v<RangeCRBeginT, NonborrowingRange&>);
+static_assert(!std::is_invocable_v<RangeCRBeginT, NonborrowingRange&&>);
+static_assert(std::is_invocable_v<RangeCRBeginT, NonborrowingRange const&>);
+static_assert(!std::is_invocable_v<RangeCRBeginT, NonborrowingRange const&&>);
+
+constexpr bool testReturnTypes() {
+  int* a[2];
+  int b[2][2];
+  struct PossiblyConstRange {
+    char*& begin();
+    char*& end();
+    const short*& begin() const;
+    const short*& end() const;
+    int*& rbegin();
+    int*& rend();
+    const long*& rbegin() const;
+    const long*& rend() const;
+  } c;
+  struct AlwaysConstRange {
+    const char*& begin();
+    const char*& end();
+    const short*& begin() const;
+    const short*& end() const;
+    const int*& rbegin();
+    const int*& rend();
+    const long*& rbegin() const;
+    const long*& rend() const;
+  } d;
+  struct NeverConstRange {
+    char*& begin();
+    char*& end();
+    short*& begin() const;
+    short& end() const;
+    int*& rbegin();
+    int*& rend();
+    long*& rbegin() const;
+    long*& rend() const;
+  } e;
+
+  static_assert(!std::ranges::constant_range<PossiblyConstRange>);
+  static_assert(std::ranges::constant_range<const PossiblyConstRange>);
+  static_assert(std::ranges::constant_range<AlwaysConstRange>);
+  static_assert(std::ranges::constant_range<const AlwaysConstRange>);
+  static_assert(!std::ranges::constant_range<NeverConstRange>);
+  static_assert(!std::ranges::constant_range<const NeverConstRange>);
+
+  ASSERT_SAME_TYPE(decltype(std::ranges::cbegin(a)), int* const*);
+  ASSERT_SAME_TYPE(decltype(std::ranges::cbegin(b)), const int(*)[2]);
+  ASSERT_SAME_TYPE(decltype(std::ranges::cbegin(c)), const short*);
+  ASSERT_SAME_TYPE(decltype(std::ranges::cbegin(d)), const char*);
+  ASSERT_SAME_TYPE(decltype(std::ranges::cbegin(e)), std::basic_const_iterator<char*>);
+
+  ASSERT_SAME_TYPE(decltype(std::ranges::crbegin(a)), std::reverse_iterator<int* const*>);
+  ASSERT_SAME_TYPE(decltype(std::ranges::crbegin(b)), std::reverse_iterator<const int(*)[2]>);
+  ASSERT_SAME_TYPE(decltype(std::ranges::crbegin(c)), const long*);
+  ASSERT_SAME_TYPE(decltype(std::ranges::crbegin(d)), const int*);
+  ASSERT_SAME_TYPE(decltype(std::ranges::crbegin(e)), std::basic_const_iterator<int*>);
+
+  return true;
+}
+
+constexpr bool testArray() {
+  int a[2];
+  int b[2][2];
+  NonborrowingRange c[2];
+
+  assert(std::ranges::cbegin(a) == a);
+  assert(std::ranges::cbegin(b) == b);
+  assert(std::ranges::cbegin(c) == c);
+
+  assert(std::ranges::crbegin(a).base() == a + 2);
+  assert(std::ranges::crbegin(b).base() == b + 2);
+  assert(std::ranges::crbegin(c).base() == c + 2);
+
+  return true;
+}
+
+struct BorrowingRange {
+  int* begin() const;
+  int* end() const;
+};
+template <>
+inline constexpr bool std::ranges::enable_borrowed_range<BorrowingRange> = true;
+
+static_assert(std::is_invocable_v<RangeCBeginT, BorrowingRange>);
+static_assert(std::is_invocable_v<RangeCBeginT, const BorrowingRange>);
+static_assert(std::is_invocable_v<RangeCBeginT, BorrowingRange&>);
+static_assert(std::is_invocable_v<RangeCBeginT, const BorrowingRange&>);
+static_assert(std::is_invocable_v<RangeCRBeginT, BorrowingRange>);
+static_assert(std::is_invocable_v<RangeCRBeginT, const BorrowingRange>);
+static_assert(std::is_invocable_v<RangeCRBeginT, BorrowingRange&>);
+static_assert(std::is_invocable_v<RangeCRBeginT, const BorrowingRange&>);
+
+struct NoThrowBeginThrowingEnd {
+  const int* begin() const noexcept;
+  const int* end() const;
+} ntbte;
+static_assert(noexcept(std::ranges::cbegin(ntbte)));
+static_assert(!noexcept(std::ranges::crbegin(ntbte)));
+
+struct ThrowingBeginNoThrowEnd {
+  const int* begin() const;
+  const int* end() const noexcept;
+} tbnte;
+static_assert(!noexcept(std::ranges::cbegin(tbnte)));
+static_assert(noexcept(std::ranges::crbegin(tbnte)));
+
+// Test ADL-proofing.
+struct Incomplete;
+template <class T>
+struct Holder {
+  T t;
+};
+static_assert(!std::is_invocable_v<RangeCBeginT, Holder<Incomplete>*>);
+static_assert(!std::is_invocable_v<RangeCBeginT, Holder<Incomplete>*&>);
+static_assert(!std::is_invocable_v<RangeCRBeginT, Holder<Incomplete>*>);
+static_assert(!std::is_invocable_v<RangeCRBeginT, Holder<Incomplete>*&>);
+
+int main(int, char**) {
+  static_assert(testReturnTypes());
+
+  testArray();
+  static_assert(testArray());
+
+  return 0;
+}
diff --git a/libcxx/test/std/ranges/range.access/cbegin.verify.cpp b/libcxx/test/std/ranges/range.access/cbegin.verify.cpp
new file mode 100644
index 00000000000000..18ac8ae65e3383
--- /dev/null
+++ b/libcxx/test/std/ranges/range.access/cbegin.verify.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// std::ranges::cbegin
+
+#include <ranges>
+
+struct NonBorrowedRange {
+  int* begin() const;
+  int* end() const;
+};
+static_assert(!std::ranges::enable_borrowed_range<NonBorrowedRange>);
+
+// Verify that if the expression is an rvalue and `enable_borrowed_range` is false, `ranges::cbegin` is ill-formed.
+void test() {
+  std::ranges::cbegin(NonBorrowedRange());
+  // expected-error-re at -1 {{{{no matching function for call to object of type 'const (std::ranges::)?__cbegin::__fn'}}}}
+}
diff --git a/libcxx/test/std/ranges/range.access/cend.pass.cpp b/libcxx/test/std/ranges/range.access/cend.pass.cpp
new file mode 100644
index 00000000000000..86cb8ac160eb37
--- /dev/null
+++ b/libcxx/test/std/ranges/range.access/cend.pass.cpp
@@ -0,0 +1,207 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// std::ranges::cend
+// std::ranges::crend
+
+#include <ranges>
+
+#include <cassert>
+#include <utility>
+#include "almost_satisfies_types.h"
+#include "test_macros.h"
+#include "test_iterators.h"
+
+using RangeCEndT  = decltype(std::ranges::cend);
+using RangeCREndT = decltype(std::ranges::crend);
+
+static_assert(!std::is_invocable_v<RangeCEndT, int (&&)[10]>);
+static_assert(std::is_invocable_v<RangeCEndT, int (&)[10]>);
+static_assert(!std::is_invocable_v<RangeCEndT, int (&&)[]>);
+static_assert(!std::is_invocable_v<RangeCEndT, int (&)[]>);
+static_assert(!std::is_invocable_v<RangeCREndT, int (&&)[10]>);
+static_assert(std::is_invocable_v<RangeCREndT, int (&)[10]>);
+static_assert(!std::is_invocable_v<RangeCREndT, int (&&)[]>);
+static_assert(!std::is_invocable_v<RangeCREndT, int (&)[]>);
+
+static_assert(!std::is_invocable_v<RangeCEndT, InputRangeNotDerivedFrom>);
+static_assert(!std::is_invocable_v<RangeCEndT, InputRangeNotIndirectlyReadable>);
+static_assert(!std::is_invocable_v<RangeCEndT, InputRangeNotInputOrOutputIterator>);
+static_assert(!std::is_invocable_v<RangeCEndT, InputRangeNotSentinelSemiregular>);
+static_assert(!std::is_invocable_v<RangeCEndT, InputRangeNotSentinelEqualityComparableWith>);
+
+static_assert(!std::is_invocable_v<RangeCREndT, BidirectionalRangeNotDerivedFrom>);
+static_assert(!std::is_invocable_v<RangeCREndT, BidirectionalRangeNotSentinelSemiregular>);
+static_assert(!std::is_invocable_v<RangeCREndT, BidirectionalRangeNotSentinelWeaklyEqualityComparableWith>);
+static_assert(!std::is_invocable_v<RangeCREndT, BidirectionalRangeNotDecrementable>);
+
+struct Incomplete;
+
+static_assert(!std::is_invocable_v<RangeCEndT, Incomplete (&&)[]>);
+static_assert(!std::is_invocable_v<RangeCEndT, const Incomplete (&&)[]>);
+static_assert(!std::is_invocable_v<RangeCEndT, Incomplete (&&)[10]>);
+static_assert(!std::is_invocable_v<RangeCEndT, const Incomplete (&&)[10]>);
+
+static_assert(!std::is_invocable_v<RangeCREndT, Incomplete (&&)[]>);
+static_assert(!std::is_invocable_v<RangeCREndT, const Incomplete (&&)[]>);
+static_assert(!std::is_invocable_v<RangeCREndT, Incomplete (&&)[10]>);
+static_assert(!std::is_invocable_v<RangeCREndT, const Incomplete (&&)[10]>);
+
+// This case is IFNDR; we handle it SFINAE-friendly.
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCEndT, Incomplete (&)[]>);
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCEndT, const Incomplete (&)[]>);
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCREndT, Incomplete (&)[]>);
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCREndT, const Incomplete (&)[]>);
+
+// This case is IFNDR; we handle it SFINAE-friendly.
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCEndT, Incomplete (&)[10]>);
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCEndT, const Incomplete (&)[10]>);
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCREndT, Incomplete (&)[10]>);
+LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCREndT, const Incomplete (&)[10]>);
+
+struct NonborrowingRange {
+  int x;
+  constexpr const int* begin() const { return &x; }
+  constexpr const int* rbegin() const { return &x; }
+  constexpr const int* end() const { return &x; }
+  constexpr const int* rend() const { return &x; }
+};
+
+// Ensure that we can't call with rvalues with borrowing disabled.
+static_assert(std::is_invocable_v<RangeCEndT, NonborrowingRange&>);
+static_assert(!std::is_invocable_v<RangeCEndT, NonborrowingRange&&>);
+static_assert(std::is_invocable_v<RangeCEndT, NonborrowingRange const&>);
+static_assert(!std::is_invocable_v<RangeCEndT, NonborrowingRange const&&>);
+static_assert(std::is_invocable_v<RangeCREndT, NonborrowingRange&>);
+static_assert(!std::is_invocable_v<RangeCREndT, NonborrowingRange&&>);
+static_assert(std::is_invocable_v<RangeCREndT, NonborrowingRange const&>);
+static_assert(!std::is_invocable_v<RangeCREndT, NonborrowingRange const&&>);
+
+constexpr bool testReturnTypes() {
+  int* a[2];
+  int b[2][2];
+  struct PossiblyConstRange {
+    char*& begin();
+    char*& end();
+    const short*& begin() const;
+    const short*& end() const;
+    int*& rbegin();
+    int*& rend();
+    const long*& rbegin() const;
+    const long*& rend() const;
+  } c;
+  struct AlwaysConstRange {
+    const char*& begin();
+    const char*& end();
+    const short*& begin() const;
+    const short*& end() const;
+    const int*& rbegin();
+    const int*& rend();
+    const long*& rbegin() const;
+    const long*& rend() const;
+  } d;
+  struct NeverConstRange {
+    char*& begin();
+    char*& end();
+    short*& begin() const;
+    short& end() const;
+    int*& rbegin();
+    int*& rend();
+    long*& rbegin() const;
+    long*& rend() const;
+  } e;
+
+  static_assert(!std::ranges::constant_range<PossiblyConstRange>);
+  static_assert(std::ranges::constant_range<const PossiblyConstRange>);
+  static_assert(std::ranges::constant_range<AlwaysConstRange>);
+  static_assert(std::ranges::constant_range<const AlwaysConstRange>);
+  static_assert(!std::ranges::constant_range<NeverConstRange>);
+  static_assert(!std::ranges::constant_range<const NeverConstRange>);
+
+  ASSERT_SAME_TYPE(decltype(std::ranges::cend(a)), int* const*);
+  ASSERT_SAME_TYPE(decltype(std::ranges::cend(b)), const int(*)[2]);
+  ASSERT_SAME_TYPE(decltype(std::ranges::cend(c)), const short*);
+  ASSERT_SAME_TYPE(decltype(std::ranges::cend(d)), const char*);
+  ASSERT_SAME_TYPE(decltype(std::ranges::cend(e)), std::basic_const_iterator<char*>);
+
+  ASSERT_SAME_TYPE(decltype(std::ranges::crend(a)), std::reverse_iterator<int* const*>);
+  ASSERT_SAME_TYPE(decltype(std::ranges::crend(b)), std::reverse_iterator<const int(*)[2]>);
+  ASSERT_SAME_TYPE(decltype(std::ranges::crend(c)), const long*);
+  ASSERT_SAME_TYPE(decltype(std::ranges::crend(d)), const int*);
+  ASSERT_SAME_TYPE(decltype(std::ranges::crend(e)), std::basic_const_iterator<int*>);
+
+  return true;
+}
+
+constexpr bool testArray() {
+  int a[2];
+  int b[2][2];
+  NonborrowingRange c[2];
+
+  assert(std::ranges::cend(a) == a + 2);
+  assert(std::ranges::cend(b) == b + 2);
+  assert(std::ranges::cend(c) == c + 2);
+
+  assert(std::ranges::crend(a).base() == a);
+  assert(std::ranges::crend(b).base() == b);
+  assert(std::ranges::crend(c).base() == c);
+
+  return true;
+}
+
+struct BorrowingRange {
+  int* begin() const;
+  int* end() const;
+};
+template <>
+inline constexpr bool std::ranges::enable_borrowed_range<BorrowingRange> = true;
+
+static_assert(std::is_invocable_v<RangeCEndT, BorrowingRange>);
+static_assert(std::is_invocable_v<RangeCEndT, const BorrowingRange>);
+static_assert(std::is_invocable_v<RangeCEndT, BorrowingRange&>);
+static_assert(std::is_invocable_v<RangeCEndT, const BorrowingRange&>);
+static_assert(std::is_invocable_v<RangeCREndT, BorrowingRange>);
+static_assert(std::is_invocable_v<RangeCREndT, const BorrowingRange>);
+static_assert(std::is_invocable_v<RangeCREndT, BorrowingRange&>);
+static_assert(std::is_invocable_v<RangeCREndT, const BorrowingRange&>);
+
+struct NoThrowEndThrowingEnd {
+  const int* begin() const noexcept;
+  const int* end() const;
+} ntbte;
+static_assert(!noexcept(std::ranges::cend(ntbte)));
+static_assert(noexcept(std::ranges::crend(ntbte)));
+
+struct ThrowingEndNoThrowEnd {
+  const int* begin() const;
+  const int* end() const noexcept;
+} tbnte;
+static_assert(noexcept(std::ranges::cend(tbnte)));
+static_assert(!noexcept(std::ranges::crend(tbnte)));
+
+// Test ADL-proofing.
+struct Incomplete;
+template <class T>
+struct Holder {
+  T t;
+};
+static_assert(!std::is_invocable_v<RangeCEndT, Holder<Incomplete>*>);
+static_assert(!std::is_invocable_v<RangeCEndT, Holder<Incomplete>*&>);
+static_assert(!std::is_invocable_v<RangeCREndT, Holder<Incomplete>*>);
+static_assert(!std::is_invocable_v<RangeCREndT, Holder<Incomplete>*&>);
+
+int main(int, char**) {
+  static_assert(testReturnTypes());
+
+  testArray();
+  static_assert(testArray());
+
+  return 0;
+}
diff --git a/libcxx/test/std/ranges/range.access/cend.verify.cpp b/libcxx/test/std/ranges/range.access/cend.verify.cpp
new file mode 100644
index 00000000000000..e50b90b4fbd490
--- /dev/null
+++ b/libcxx/test/std/ranges/range.access/cend.verify.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// std::ranges::cend
+
+#include <ranges>
+
+struct NonBorrowedRange {
+  int* begin() const;
+  int* end() const;
+};
+static_assert(!std::ranges::enable_borrowed_range<NonBorrowedRange>);
+
+// Verify that if the expression is an rvalue and `enable_borrowed_range` is false, `ranges::cend` is ill-formed.
+void test() {
+  std::ranges::cend(NonBorrowedRange());
+  // expected-error-re at -1 {{{{no matching function for call to object of type 'const (std::ranges::)?__cend::__fn'}}}}
+}
diff --git a/libcxx/test/std/ranges/range.access/end.pass.cpp b/libcxx/test/std/ranges/range.access/end.pass.cpp
index 3e465b357e9851..3197634c2d97f0 100644
--- a/libcxx/test/std/ranges/range.access/end.pass.cpp
+++ b/libcxx/test/std/ranges/range.access/end.pass.cpp
@@ -9,7 +9,7 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 
 // std::ranges::end
-// std::ranges::cend
+// std::ranges::cend // until C++23
 
 #include <ranges>
 
@@ -19,7 +19,9 @@
 #include "test_iterators.h"
 
 using RangeEndT = decltype(std::ranges::end);
+#if TEST_STD_VER < 23
 using RangeCEndT = decltype(std::ranges::cend);
+#endif // TEST_STD_VER < 23
 
 static int globalBuff[8];
 
@@ -27,16 +29,20 @@ static_assert(!std::is_invocable_v<RangeEndT, int (&&)[]>);
 static_assert(!std::is_invocable_v<RangeEndT, int (&)[]>);
 static_assert(!std::is_invocable_v<RangeEndT, int (&&)[10]>);
 static_assert( std::is_invocable_v<RangeEndT, int (&)[10]>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCEndT, int (&&)[]>);
 static_assert(!std::is_invocable_v<RangeCEndT, int (&)[]>);
 static_assert(!std::is_invocable_v<RangeCEndT, int (&&)[10]>);
 static_assert( std::is_invocable_v<RangeCEndT, int (&)[10]>);
+#endif // TEST_STD_VER < 23
 
 struct Incomplete;
 static_assert(!std::is_invocable_v<RangeEndT, Incomplete(&&)[]>);
 static_assert(!std::is_invocable_v<RangeEndT, Incomplete(&&)[42]>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCEndT, Incomplete(&&)[]>);
 static_assert(!std::is_invocable_v<RangeCEndT, Incomplete(&&)[42]>);
+#endif // TEST_STD_VER < 23
 
 struct EndMember {
   int x;
@@ -49,47 +55,50 @@ static_assert( std::is_invocable_v<RangeEndT, EndMember &>);
 static_assert(!std::is_invocable_v<RangeEndT, EndMember &&>);
 static_assert( std::is_invocable_v<RangeEndT, EndMember const&>);
 static_assert(!std::is_invocable_v<RangeEndT, EndMember const&&>);
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCEndT, EndMember &>);
 static_assert(!std::is_invocable_v<RangeCEndT, EndMember &&>);
 static_assert( std::is_invocable_v<RangeCEndT, EndMember const&>);
 static_assert(!std::is_invocable_v<RangeCEndT, EndMember const&&>);
+#endif // TEST_STD_VER < 23
 
 constexpr bool testReturnTypes() {
-  {
-    int *x[2];
-    ASSERT_SAME_TYPE(decltype(std::ranges::end(x)), int**);
-    ASSERT_SAME_TYPE(decltype(std::ranges::cend(x)), int* const*);
-  }
-  {
-    int x[2][2];
-    ASSERT_SAME_TYPE(decltype(std::ranges::end(x)), int(*)[2]);
-    ASSERT_SAME_TYPE(decltype(std::ranges::cend(x)), const int(*)[2]);
-  }
-  {
-    struct Different {
-      char *begin();
-      sentinel_wrapper<char*>& end();
-      short *begin() const;
-      sentinel_wrapper<short*>& end() const;
-    } x;
-    ASSERT_SAME_TYPE(decltype(std::ranges::end(x)), sentinel_wrapper<char*>);
-    ASSERT_SAME_TYPE(decltype(std::ranges::cend(x)), sentinel_wrapper<short*>);
-  }
+  int* a[2];
+  int b[2][2];
+  struct Different {
+    char* begin();
+    sentinel_wrapper<char*>& end();
+    short* begin() const;
+    sentinel_wrapper<short*>& end() const;
+  } c;
+
+  ASSERT_SAME_TYPE(decltype(std::ranges::end(a)), int**);
+  ASSERT_SAME_TYPE(decltype(std::ranges::end(b)), int(*)[2]);
+  ASSERT_SAME_TYPE(decltype(std::ranges::end(c)), sentinel_wrapper<char*>);
+
+#if TEST_STD_VER < 23
+  ASSERT_SAME_TYPE(decltype(std::ranges::cend(a)), int* const*);
+  ASSERT_SAME_TYPE(decltype(std::ranges::cend(b)), const int(*)[2]);
+  ASSERT_SAME_TYPE(decltype(std::ranges::cend(c)), sentinel_wrapper<short*>);
+#endif // TEST_STD_VER < 23
+
   return true;
 }
 
 constexpr bool testArray() {
   int a[2];
-  assert(std::ranges::end(a) == a + 2);
-  assert(std::ranges::cend(a) == a + 2);
-
   int b[2][2];
-  assert(std::ranges::end(b) == b + 2);
-  assert(std::ranges::cend(b) == b + 2);
-
   EndMember c[2];
+
+  assert(std::ranges::end(a) == a + 2);
+  assert(std::ranges::end(b) == b + 2);
   assert(std::ranges::end(c) == c + 2);
+
+#if TEST_STD_VER < 23
+  assert(std::ranges::cend(a) == a + 2);
+  assert(std::ranges::cend(b) == b + 2);
   assert(std::ranges::cend(c) == c + 2);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
@@ -127,8 +136,10 @@ struct NonConstEndMember {
 };
 static_assert( std::is_invocable_v<RangeEndT,  NonConstEndMember &>);
 static_assert(!std::is_invocable_v<RangeEndT,  NonConstEndMember const&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCEndT, NonConstEndMember &>);
 static_assert(!std::is_invocable_v<RangeCEndT, NonConstEndMember const&>);
+#endif // TEST_STD_VER < 23
 
 struct EnabledBorrowingEndMember {
   constexpr int *begin() const { return nullptr; }
@@ -160,24 +171,24 @@ struct EmptyPtrEndMember {
 
 constexpr bool testEndMember() {
   EndMember a;
-  assert(std::ranges::end(a) == &a.x);
-  assert(std::ranges::cend(a) == &a.x);
-
   NonConstEndMember b;
-  assert(std::ranges::end(b) == &b.x);
-  static_assert(!std::is_invocable_v<RangeCEndT, decltype((b))>);
-
   EnabledBorrowingEndMember c;
-  assert(std::ranges::end(std::move(c)) == &globalBuff[0]);
-  assert(std::ranges::cend(std::move(c)) == &globalBuff[0]);
-
   EndMemberFunction d;
-  assert(std::ranges::end(d) == &d.x);
-  assert(std::ranges::cend(d) == &d.x);
-
   EmptyPtrEndMember e;
+
+  assert(std::ranges::end(a) == &a.x);
+  assert(std::ranges::end(b) == &b.x);
+  assert(std::ranges::end(std::move(c)) == &globalBuff[0]);
+  assert(std::ranges::end(d) == &d.x);
   assert(std::ranges::end(e) == &e.x);
+
+#if TEST_STD_VER < 23
+  assert(std::ranges::cend(a) == &a.x);
+  static_assert(!std::is_invocable_v<RangeCEndT, decltype((b))>);
+  assert(std::ranges::cend(std::move(c)) == &globalBuff[0]);
+  assert(std::ranges::cend(d) == &d.x);
   assert(std::ranges::cend(e) == &e.x);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
@@ -194,8 +205,10 @@ static_assert(!std::is_invocable_v<RangeEndT, EndFunction &&>);
 static_assert( std::is_invocable_v<RangeEndT,  EndFunction const&>);
 static_assert(!std::is_invocable_v<RangeEndT,  EndFunction &&>);
 static_assert(std::is_invocable_v<RangeEndT, EndFunction&>); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCEndT, EndFunction const&>);
 static_assert( std::is_invocable_v<RangeCEndT, EndFunction &>);
+#endif // TEST_STD_VER < 23
 
 struct EndFunctionReturnsInt {
   friend constexpr int begin(EndFunctionReturnsInt const&);
@@ -230,7 +243,9 @@ struct EndFunctionByValue {
   friend constexpr int *begin(EndFunctionByValue) { return nullptr; }
   friend constexpr int *end(EndFunctionByValue) { return &globalBuff[1]; }
 };
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCEndT, EndFunctionByValue>);
+#endif // TEST_STD_VER < 23
 
 struct EndFunctionEnabledBorrowing {
   friend constexpr int *begin(EndFunctionEnabledBorrowing) { return nullptr; }
@@ -268,61 +283,63 @@ struct BeginMemberEndFunction {
 
 constexpr bool testEndFunction() {
   const EndFunction a{};
-  assert(std::ranges::end(a) == &a.x);
-  assert(std::ranges::cend(a) == &a.x);
   EndFunction aa{};
-  assert(std::ranges::end(aa) == &aa.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
-  assert(std::ranges::cend(aa) == &aa.x);
-
   EndFunctionByValue b;
-  assert(std::ranges::end(b) == &globalBuff[1]);
-  assert(std::ranges::cend(b) == &globalBuff[1]);
-
   EndFunctionEnabledBorrowing c;
-  assert(std::ranges::end(std::move(c)) == &globalBuff[2]);
-  assert(std::ranges::cend(std::move(c)) == &globalBuff[2]);
-
   const EndFunctionReturnsEmptyPtr d{};
-  assert(std::ranges::end(d) == &d.x);
-  assert(std::ranges::cend(d) == &d.x);
   EndFunctionReturnsEmptyPtr dd{};
-  assert(std::ranges::end(dd) == &dd.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
-  assert(std::ranges::cend(dd) == &dd.x);
-
   const EndFunctionWithDataMember e{};
-  assert(std::ranges::end(e) == &e.x);
-  assert(std::ranges::cend(e) == &e.x);
   EndFunctionWithDataMember ee{};
-  assert(std::ranges::end(ee) == &ee.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
-  assert(std::ranges::cend(ee) == &ee.x);
-
   const EndFunctionWithPrivateEndMember f{};
-  assert(std::ranges::end(f) == &f.y);
-  assert(std::ranges::cend(f) == &f.y);
   EndFunctionWithPrivateEndMember ff{};
-  assert(std::ranges::end(ff) == &ff.y); // Ill-formed before P2602R2 Poison Pills are Too Toxic
-  assert(std::ranges::cend(ff) == &ff.y);
-
   const BeginMemberEndFunction g{};
-  assert(std::ranges::end(g) == &g.x);
-  assert(std::ranges::cend(g) == &g.x);
   BeginMemberEndFunction gg{};
+
+  assert(std::ranges::end(a) == &a.x);
+  assert(std::ranges::end(aa) == &aa.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+  assert(std::ranges::end(b) == &globalBuff[1]);
+  assert(std::ranges::end(std::move(c)) == &globalBuff[2]);
+  assert(std::ranges::end(d) == &d.x);
+  assert(std::ranges::end(dd) == &dd.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+  assert(std::ranges::end(e) == &e.x);
+  assert(std::ranges::end(ee) == &ee.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+  assert(std::ranges::end(f) == &f.y);
+  assert(std::ranges::end(ff) == &ff.y); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+  assert(std::ranges::end(g) == &g.x);
   assert(std::ranges::end(gg) == &gg.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+
+#if TEST_STD_VER < 23
+  assert(std::ranges::cend(a) == &a.x);
+  assert(std::ranges::cend(aa) == &aa.x);
+  assert(std::ranges::cend(b) == &globalBuff[1]);
+  assert(std::ranges::cend(std::move(c)) == &globalBuff[2]);
+  assert(std::ranges::cend(d) == &d.x);
+  assert(std::ranges::cend(dd) == &dd.x);
+  assert(std::ranges::cend(e) == &e.x);
+  assert(std::ranges::cend(ee) == &ee.x);
+  assert(std::ranges::cend(f) == &f.y);
+  assert(std::ranges::cend(ff) == &ff.y);
+  assert(std::ranges::cend(g) == &g.x);
   assert(std::ranges::cend(gg) == &gg.x);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
 
 
 ASSERT_NOEXCEPT(std::ranges::end(std::declval<int (&)[10]>()));
+#if TEST_STD_VER < 23
 ASSERT_NOEXCEPT(std::ranges::cend(std::declval<int (&)[10]>()));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowMemberEnd {
   ThrowingIterator<int> begin() const;
   ThrowingIterator<int> end() const noexcept; // auto(t.end()) doesn't throw
 } ntme;
 static_assert(noexcept(std::ranges::end(ntme)));
+#if TEST_STD_VER < 23
 static_assert(noexcept(std::ranges::cend(ntme)));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowADLEnd {
   ThrowingIterator<int> begin() const;
@@ -330,29 +347,37 @@ struct NoThrowADLEnd {
   friend ThrowingIterator<int> end(const NoThrowADLEnd&) noexcept;
 } ntae;
 static_assert(noexcept(std::ranges::end(ntae)));
+#if TEST_STD_VER < 23
 static_assert(noexcept(std::ranges::cend(ntae)));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowMemberEndReturnsRef {
   ThrowingIterator<int> begin() const;
   ThrowingIterator<int>& end() const noexcept; // auto(t.end()) may throw
 } ntmerr;
 static_assert(!noexcept(std::ranges::end(ntmerr)));
+#if TEST_STD_VER < 23
 static_assert(!noexcept(std::ranges::cend(ntmerr)));
+#endif // TEST_STD_VER < 23
 
 struct EndReturnsArrayRef {
     auto begin() const noexcept -> int(&)[10];
     auto end() const noexcept -> int(&)[10];
 } erar;
 static_assert(noexcept(std::ranges::end(erar)));
+#if TEST_STD_VER < 23
 static_assert(noexcept(std::ranges::cend(erar)));
+#endif // TEST_STD_VER < 23
 
 // Test ADL-proofing.
 struct Incomplete;
 template<class T> struct Holder { T t; };
 static_assert(!std::is_invocable_v<RangeEndT, Holder<Incomplete>*>);
 static_assert(!std::is_invocable_v<RangeEndT, Holder<Incomplete>*&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCEndT, Holder<Incomplete>*>);
 static_assert(!std::is_invocable_v<RangeCEndT, Holder<Incomplete>*&>);
+#endif // TEST_STD_VER < 23
 
 int main(int, char**) {
   static_assert(testReturnTypes());
diff --git a/libcxx/test/std/ranges/range.access/rbegin.pass.cpp b/libcxx/test/std/ranges/range.access/rbegin.pass.cpp
index 3997f38efd0298..7919b84d2b35a0 100644
--- a/libcxx/test/std/ranges/range.access/rbegin.pass.cpp
+++ b/libcxx/test/std/ranges/range.access/rbegin.pass.cpp
@@ -9,7 +9,7 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 
 // std::ranges::rbegin
-// std::ranges::crbegin
+// std::ranges::crbegin // until C++23
 
 #include <ranges>
 
@@ -19,7 +19,9 @@
 #include "test_iterators.h"
 
 using RangeRBeginT = decltype(std::ranges::rbegin);
+#if TEST_STD_VER < 23
 using RangeCRBeginT = decltype(std::ranges::crbegin);
+#endif // TEST_STD_VER < 23
 
 static int globalBuff[8];
 
@@ -27,34 +29,42 @@ static_assert(!std::is_invocable_v<RangeRBeginT, int (&&)[10]>);
 static_assert( std::is_invocable_v<RangeRBeginT, int (&)[10]>);
 static_assert(!std::is_invocable_v<RangeRBeginT, int (&&)[]>);
 static_assert(!std::is_invocable_v<RangeRBeginT, int (&)[]>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCRBeginT, int (&&)[10]>);
 static_assert( std::is_invocable_v<RangeCRBeginT, int (&)[10]>);
 static_assert(!std::is_invocable_v<RangeCRBeginT, int (&&)[]>);
 static_assert(!std::is_invocable_v<RangeCRBeginT, int (&)[]>);
+#endif // TEST_STD_VER < 23
 
 struct Incomplete;
 
 static_assert(!std::is_invocable_v<RangeRBeginT, Incomplete(&&)[]>);
-static_assert(!std::is_invocable_v<RangeRBeginT, const Incomplete(&&)[]>);
-static_assert(!std::is_invocable_v<RangeCRBeginT, Incomplete(&&)[]>);
-static_assert(!std::is_invocable_v<RangeCRBeginT, const Incomplete(&&)[]>);
-
+static_assert(!std::is_invocable_v<RangeRBeginT, const Incomplete (&&)[]>);
 static_assert(!std::is_invocable_v<RangeRBeginT, Incomplete(&&)[10]>);
 static_assert(!std::is_invocable_v<RangeRBeginT, const Incomplete(&&)[10]>);
+
+#if TEST_STD_VER < 23
+static_assert(!std::is_invocable_v<RangeCRBeginT, Incomplete (&&)[]>);
+static_assert(!std::is_invocable_v<RangeCRBeginT, const Incomplete (&&)[]>);
 static_assert(!std::is_invocable_v<RangeCRBeginT, Incomplete(&&)[10]>);
 static_assert(!std::is_invocable_v<RangeCRBeginT, const Incomplete(&&)[10]>);
+#endif // TEST_STD_VER < 23
 
 // This case is IFNDR; we handle it SFINAE-friendly.
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeRBeginT, Incomplete(&)[]>);
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeRBeginT, const Incomplete(&)[]>);
+#if TEST_STD_VER < 23
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCRBeginT, Incomplete(&)[]>);
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCRBeginT, const Incomplete(&)[]>);
+#endif // TEST_STD_VER < 23
 
 // This case is IFNDR; we handle it SFINAE-friendly.
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeRBeginT, Incomplete(&)[10]>);
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeRBeginT, const Incomplete(&)[10]>);
+#if TEST_STD_VER < 23
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCRBeginT, Incomplete(&)[10]>);
 LIBCPP_STATIC_ASSERT(!std::is_invocable_v<RangeCRBeginT, const Incomplete(&)[10]>);
+#endif // TEST_STD_VER < 23
 
 struct RBeginMember {
   int x;
@@ -66,45 +76,48 @@ static_assert( std::is_invocable_v<RangeRBeginT, RBeginMember &>);
 static_assert(!std::is_invocable_v<RangeRBeginT, RBeginMember &&>);
 static_assert( std::is_invocable_v<RangeRBeginT, RBeginMember const&>);
 static_assert(!std::is_invocable_v<RangeRBeginT, RBeginMember const&&>);
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCRBeginT, RBeginMember &>);
 static_assert(!std::is_invocable_v<RangeCRBeginT, RBeginMember &&>);
 static_assert( std::is_invocable_v<RangeCRBeginT, RBeginMember const&>);
 static_assert(!std::is_invocable_v<RangeCRBeginT, RBeginMember const&&>);
+#endif // TEST_STD_VER < 23
 
 constexpr bool testReturnTypes() {
-  {
-    int *x[2];
-    ASSERT_SAME_TYPE(decltype(std::ranges::rbegin(x)), std::reverse_iterator<int**>);
-    ASSERT_SAME_TYPE(decltype(std::ranges::crbegin(x)), std::reverse_iterator<int* const*>);
-  }
-  {
-    int x[2][2];
-    ASSERT_SAME_TYPE(decltype(std::ranges::rbegin(x)), std::reverse_iterator<int(*)[2]>);
-    ASSERT_SAME_TYPE(decltype(std::ranges::crbegin(x)), std::reverse_iterator<const int(*)[2]>);
-  }
-  {
-    struct Different {
-      char*& rbegin();
-      short*& rbegin() const;
-    } x;
-    ASSERT_SAME_TYPE(decltype(std::ranges::rbegin(x)), char*);
-    ASSERT_SAME_TYPE(decltype(std::ranges::crbegin(x)), short*);
-  }
+  int* a[2];
+  int b[2][2];
+  struct Different {
+    char*& rbegin();
+    short*& rbegin() const;
+  } c;
+
+  ASSERT_SAME_TYPE(decltype(std::ranges::rbegin(a)), std::reverse_iterator<int**>);
+  ASSERT_SAME_TYPE(decltype(std::ranges::rbegin(b)), std::reverse_iterator<int(*)[2]>);
+  ASSERT_SAME_TYPE(decltype(std::ranges::rbegin(c)), char*);
+
+#if TEST_STD_VER < 23
+  ASSERT_SAME_TYPE(decltype(std::ranges::crbegin(a)), std::reverse_iterator<int* const*>);
+  ASSERT_SAME_TYPE(decltype(std::ranges::crbegin(b)), std::reverse_iterator<const int(*)[2]>);
+  ASSERT_SAME_TYPE(decltype(std::ranges::crbegin(c)), short*);
+#endif // TEST_STD_VER < 23
+
   return true;
 }
 
 constexpr bool testArray() {
   int a[2];
-  assert(std::ranges::rbegin(a).base() == a + 2);
-  assert(std::ranges::crbegin(a).base() == a + 2);
-
   int b[2][2];
-  assert(std::ranges::rbegin(b).base() == b + 2);
-  assert(std::ranges::crbegin(b).base() == b + 2);
-
   RBeginMember c[2];
+
+  assert(std::ranges::rbegin(a).base() == a + 2);
+  assert(std::ranges::rbegin(b).base() == b + 2);
   assert(std::ranges::rbegin(c).base() == c + 2);
+
+#if TEST_STD_VER < 23
+  assert(std::ranges::crbegin(a).base() == a + 2);
+  assert(std::ranges::crbegin(b).base() == b + 2);
   assert(std::ranges::crbegin(c).base() == c + 2);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
@@ -131,8 +144,10 @@ struct NonConstRBeginMember {
 };
 static_assert( std::is_invocable_v<RangeRBeginT,  NonConstRBeginMember &>);
 static_assert(!std::is_invocable_v<RangeRBeginT,  NonConstRBeginMember const&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCRBeginT, NonConstRBeginMember &>);
 static_assert(!std::is_invocable_v<RangeCRBeginT, NonConstRBeginMember const&>);
+#endif // TEST_STD_VER < 23
 
 struct EnabledBorrowingRBeginMember {
   constexpr int *rbegin() const { return globalBuff; }
@@ -154,28 +169,28 @@ struct EmptyPtrRBeginMember {
 
 constexpr bool testRBeginMember() {
   RBeginMember a;
+  NonConstRBeginMember b;
+  EnabledBorrowingRBeginMember c;
+  RBeginMemberFunction d;
+  EmptyPtrRBeginMember e;
+
   assert(std::ranges::rbegin(a) == &a.x);
-  assert(std::ranges::crbegin(a) == &a.x);
   static_assert(!std::is_invocable_v<RangeRBeginT, RBeginMember&&>);
-  static_assert(!std::is_invocable_v<RangeCRBeginT, RBeginMember&&>);
-
-  NonConstRBeginMember b;
   assert(std::ranges::rbegin(b) == &b.x);
-  static_assert(!std::is_invocable_v<RangeCRBeginT, NonConstRBeginMember&>);
-
-  EnabledBorrowingRBeginMember c;
   assert(std::ranges::rbegin(c) == globalBuff);
-  assert(std::ranges::crbegin(c) == globalBuff);
   assert(std::ranges::rbegin(std::move(c)) == globalBuff);
-  assert(std::ranges::crbegin(std::move(c)) == globalBuff);
-
-  RBeginMemberFunction d;
   assert(std::ranges::rbegin(d) == &d.x);
-  assert(std::ranges::crbegin(d) == &d.x);
-
-  EmptyPtrRBeginMember e;
   assert(std::ranges::rbegin(e) == &e.x);
+
+#if TEST_STD_VER < 23
+  assert(std::ranges::crbegin(a) == &a.x);
+  static_assert(!std::is_invocable_v<RangeCRBeginT, RBeginMember&&>);
+  static_assert(!std::is_invocable_v<RangeCRBeginT, NonConstRBeginMember&>);
+  assert(std::ranges::crbegin(c) == globalBuff);
+  assert(std::ranges::crbegin(std::move(c)) == globalBuff);
+  assert(std::ranges::crbegin(d) == &d.x);
   assert(std::ranges::crbegin(e) == &e.x);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
@@ -189,8 +204,10 @@ static_assert( std::is_invocable_v<RangeRBeginT,  RBeginFunction const&>);
 static_assert(!std::is_invocable_v<RangeRBeginT,  RBeginFunction &&>);
 static_assert(
     std::is_invocable_v<RangeRBeginT, RBeginFunction&>); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCRBeginT, RBeginFunction const&>);
 static_assert( std::is_invocable_v<RangeCRBeginT, RBeginFunction &>);
+#endif // TEST_STD_VER < 23
 
 struct RBeginFunctionReturnsInt {
   friend int rbegin(RBeginFunctionReturnsInt const&);
@@ -217,7 +234,9 @@ static_assert(!std::is_invocable_v<RangeRBeginT, RBeginFunctionReturnsPtrConvert
 struct RBeginFunctionByValue {
   friend constexpr int *rbegin(RBeginFunctionByValue) { return globalBuff + 1; }
 };
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCRBeginT, RBeginFunctionByValue>);
+#endif // TEST_STD_VER < 23
 
 struct RBeginFunctionEnabledBorrowing {
   friend constexpr int *rbegin(RBeginFunctionEnabledBorrowing) { return globalBuff + 2; }
@@ -247,45 +266,44 @@ struct RBeginFunctionWithPrivateBeginMember {
 constexpr bool testRBeginFunction() {
   RBeginFunction a{};
   const RBeginFunction aa{};
-  assert(std::ranges::rbegin(a) == &a.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
-  assert(std::ranges::crbegin(a) == &a.x);
-  assert(std::ranges::rbegin(aa) == &aa.x);
-  assert(std::ranges::crbegin(aa) == &aa.x);
-
   RBeginFunctionByValue b{};
   const RBeginFunctionByValue bb{};
-  assert(std::ranges::rbegin(b) == globalBuff + 1);
-  assert(std::ranges::crbegin(b) == globalBuff + 1);
-  assert(std::ranges::rbegin(bb) == globalBuff + 1);
-  assert(std::ranges::crbegin(bb) == globalBuff + 1);
-
   RBeginFunctionEnabledBorrowing c{};
   const RBeginFunctionEnabledBorrowing cc{};
-  assert(std::ranges::rbegin(std::move(c)) == globalBuff + 2);
-  assert(std::ranges::crbegin(std::move(c)) == globalBuff + 2);
-  assert(std::ranges::rbegin(std::move(cc)) == globalBuff + 2);
-  assert(std::ranges::crbegin(std::move(cc)) == globalBuff + 2);
-
   RBeginFunctionReturnsEmptyPtr d{};
   const RBeginFunctionReturnsEmptyPtr dd{};
-  assert(std::ranges::rbegin(d) == &d.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
-  assert(std::ranges::crbegin(d) == &d.x);
-  assert(std::ranges::rbegin(dd) == &dd.x);
-  assert(std::ranges::crbegin(dd) == &dd.x);
-
   RBeginFunctionWithDataMember e{};
   const RBeginFunctionWithDataMember ee{};
+  RBeginFunctionWithPrivateBeginMember f{};
+  const RBeginFunctionWithPrivateBeginMember ff{};
+
+  assert(std::ranges::rbegin(a) == &a.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+  assert(std::ranges::rbegin(aa) == &aa.x);
+  assert(std::ranges::rbegin(b) == globalBuff + 1);
+  assert(std::ranges::rbegin(bb) == globalBuff + 1);
+  assert(std::ranges::rbegin(std::move(c)) == globalBuff + 2);
+  assert(std::ranges::rbegin(std::move(cc)) == globalBuff + 2);
+  assert(std::ranges::rbegin(d) == &d.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+  assert(std::ranges::rbegin(dd) == &dd.x);
   assert(std::ranges::rbegin(e) == &e.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
   assert(std::ranges::rbegin(ee) == &ee.x);
+  assert(std::ranges::rbegin(f) == &f.y); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+  assert(std::ranges::rbegin(ff) == &ff.y);
+
+#if TEST_STD_VER < 23
+  assert(std::ranges::crbegin(a) == &a.x);
+  assert(std::ranges::crbegin(aa) == &aa.x);
+  assert(std::ranges::crbegin(b) == globalBuff + 1);
+  assert(std::ranges::crbegin(bb) == globalBuff + 1);
+  assert(std::ranges::crbegin(std::move(c)) == globalBuff + 2);
+  assert(std::ranges::crbegin(std::move(cc)) == globalBuff + 2);
+  assert(std::ranges::crbegin(d) == &d.x);
+  assert(std::ranges::crbegin(dd) == &dd.x);
   assert(std::ranges::crbegin(e) == &e.x);
   assert(std::ranges::crbegin(ee) == &ee.x);
-
-  RBeginFunctionWithPrivateBeginMember f{};
-  const RBeginFunctionWithPrivateBeginMember ff{};
-  assert(std::ranges::rbegin(f) == &f.y); // Ill-formed before P2602R2 Poison Pills are Too Toxic
   assert(std::ranges::crbegin(f) == &f.y);
-  assert(std::ranges::rbegin(ff) == &ff.y);
   assert(std::ranges::crbegin(ff) == &ff.y);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
@@ -301,7 +319,9 @@ struct MemberBeginEnd {
 };
 static_assert( std::is_invocable_v<RangeRBeginT, MemberBeginEnd&>);
 static_assert( std::is_invocable_v<RangeRBeginT, MemberBeginEnd const&>);
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCRBeginT, MemberBeginEnd const&>);
+#endif // TEST_STD_VER < 23
 
 struct FunctionBeginEnd {
   int b, e;
@@ -319,7 +339,9 @@ struct FunctionBeginEnd {
 };
 static_assert( std::is_invocable_v<RangeRBeginT, FunctionBeginEnd&>);
 static_assert( std::is_invocable_v<RangeRBeginT, FunctionBeginEnd const&>);
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCRBeginT, FunctionBeginEnd const&>);
+#endif // TEST_STD_VER < 23
 
 struct MemberBeginFunctionEnd {
   int b, e;
@@ -335,7 +357,9 @@ struct MemberBeginFunctionEnd {
 };
 static_assert( std::is_invocable_v<RangeRBeginT, MemberBeginFunctionEnd&>);
 static_assert( std::is_invocable_v<RangeRBeginT, MemberBeginFunctionEnd const&>);
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCRBeginT, MemberBeginFunctionEnd const&>);
+#endif // TEST_STD_VER < 23
 
 struct FunctionBeginMemberEnd {
   int b, e;
@@ -351,59 +375,77 @@ struct FunctionBeginMemberEnd {
 };
 static_assert( std::is_invocable_v<RangeRBeginT, FunctionBeginMemberEnd&>);
 static_assert( std::is_invocable_v<RangeRBeginT, FunctionBeginMemberEnd const&>);
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCRBeginT, FunctionBeginMemberEnd const&>);
+#endif // TEST_STD_VER < 23
 
 struct MemberBeginEndDifferentTypes {
   bidirectional_iterator<int*> begin();
   bidirectional_iterator<const int*> end();
 };
 static_assert(!std::is_invocable_v<RangeRBeginT, MemberBeginEndDifferentTypes&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCRBeginT, MemberBeginEndDifferentTypes&>);
+#endif // TEST_STD_VER < 23
 
 struct FunctionBeginEndDifferentTypes {
   friend bidirectional_iterator<int*> begin(FunctionBeginEndDifferentTypes&);
   friend bidirectional_iterator<const int*> end(FunctionBeginEndDifferentTypes&);
 };
 static_assert(!std::is_invocable_v<RangeRBeginT, FunctionBeginEndDifferentTypes&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCRBeginT, FunctionBeginEndDifferentTypes&>);
+#endif // TEST_STD_VER < 23
 
 struct MemberBeginEndForwardIterators {
   forward_iterator<int*> begin();
   forward_iterator<int*> end();
 };
 static_assert(!std::is_invocable_v<RangeRBeginT, MemberBeginEndForwardIterators&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCRBeginT, MemberBeginEndForwardIterators&>);
+#endif // TEST_STD_VER < 23
 
 struct FunctionBeginEndForwardIterators {
   friend forward_iterator<int*> begin(FunctionBeginEndForwardIterators&);
   friend forward_iterator<int*> end(FunctionBeginEndForwardIterators&);
 };
 static_assert(!std::is_invocable_v<RangeRBeginT, FunctionBeginEndForwardIterators&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCRBeginT, FunctionBeginEndForwardIterators&>);
+#endif // TEST_STD_VER < 23
 
 struct MemberBeginOnly {
   bidirectional_iterator<int*> begin() const;
 };
 static_assert(!std::is_invocable_v<RangeRBeginT, MemberBeginOnly&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCRBeginT, MemberBeginOnly&>);
+#endif // TEST_STD_VER < 23
 
 struct FunctionBeginOnly {
   friend bidirectional_iterator<int*> begin(FunctionBeginOnly&);
 };
 static_assert(!std::is_invocable_v<RangeRBeginT, FunctionBeginOnly&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCRBeginT, FunctionBeginOnly&>);
+#endif // TEST_STD_VER < 23
 
 struct MemberEndOnly {
   bidirectional_iterator<int*> end() const;
 };
 static_assert(!std::is_invocable_v<RangeRBeginT, MemberEndOnly&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCRBeginT, MemberEndOnly&>);
+#endif // TEST_STD_VER < 23
 
 struct FunctionEndOnly {
   friend bidirectional_iterator<int*> end(FunctionEndOnly&);
 };
 static_assert(!std::is_invocable_v<RangeRBeginT, FunctionEndOnly&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCRBeginT, FunctionEndOnly&>);
+#endif // TEST_STD_VER < 23
 
 // Make sure there is no clash between the following cases:
 // - the case that handles classes defining member `rbegin` and `rend` functions;
@@ -414,93 +456,112 @@ struct MemberBeginAndRBegin {
   int* rbegin() const;
   int* rend() const;
 };
-static_assert( std::is_invocable_v<RangeRBeginT, MemberBeginAndRBegin&>);
-static_assert( std::is_invocable_v<RangeCRBeginT, MemberBeginAndRBegin&>);
+static_assert(std::is_invocable_v<RangeRBeginT, MemberBeginAndRBegin&>);
 static_assert( std::same_as<std::invoke_result_t<RangeRBeginT, MemberBeginAndRBegin&>, int*>);
+#if TEST_STD_VER < 23
+static_assert(std::is_invocable_v<RangeCRBeginT, MemberBeginAndRBegin&>);
 static_assert( std::same_as<std::invoke_result_t<RangeCRBeginT, MemberBeginAndRBegin&>, int*>);
+#endif // TEST_STD_VER < 23
 
 constexpr bool testBeginEnd() {
   MemberBeginEnd a{};
   const MemberBeginEnd aa{};
-  assert(base(std::ranges::rbegin(a).base()) == &a.e);
-  assert(base(std::ranges::crbegin(a).base()) == &a.ce);
-  assert(base(std::ranges::rbegin(aa).base()) == &aa.ce);
-  assert(base(std::ranges::crbegin(aa).base()) == &aa.ce);
-
   FunctionBeginEnd b{};
   const FunctionBeginEnd bb{};
-  assert(base(std::ranges::rbegin(b).base()) == &b.e);
-  assert(base(std::ranges::crbegin(b).base()) == &b.ce);
-  assert(base(std::ranges::rbegin(bb).base()) == &bb.ce);
-  assert(base(std::ranges::crbegin(bb).base()) == &bb.ce);
-
   MemberBeginFunctionEnd c{};
   const MemberBeginFunctionEnd cc{};
-  assert(base(std::ranges::rbegin(c).base()) == &c.e);
-  assert(base(std::ranges::crbegin(c).base()) == &c.ce);
-  assert(base(std::ranges::rbegin(cc).base()) == &cc.ce);
-  assert(base(std::ranges::crbegin(cc).base()) == &cc.ce);
-
   FunctionBeginMemberEnd d{};
   const FunctionBeginMemberEnd dd{};
+
+  assert(base(std::ranges::rbegin(a).base()) == &a.e);
+  assert(base(std::ranges::rbegin(aa).base()) == &aa.ce);
+  assert(base(std::ranges::rbegin(b).base()) == &b.e);
+  assert(base(std::ranges::rbegin(bb).base()) == &bb.ce);
+  assert(base(std::ranges::rbegin(c).base()) == &c.e);
+  assert(base(std::ranges::rbegin(cc).base()) == &cc.ce);
   assert(base(std::ranges::rbegin(d).base()) == &d.e);
-  assert(base(std::ranges::crbegin(d).base()) == &d.ce);
   assert(base(std::ranges::rbegin(dd).base()) == &dd.ce);
+
+#if TEST_STD_VER < 23
+  assert(base(std::ranges::crbegin(a).base()) == &a.ce);
+  assert(base(std::ranges::crbegin(aa).base()) == &aa.ce);
+  assert(base(std::ranges::crbegin(b).base()) == &b.ce);
+  assert(base(std::ranges::crbegin(bb).base()) == &bb.ce);
+  assert(base(std::ranges::crbegin(c).base()) == &c.ce);
+  assert(base(std::ranges::crbegin(cc).base()) == &cc.ce);
+  assert(base(std::ranges::crbegin(d).base()) == &d.ce);
   assert(base(std::ranges::crbegin(dd).base()) == &dd.ce);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
 
 
 ASSERT_NOEXCEPT(std::ranges::rbegin(std::declval<int (&)[10]>()));
+#if TEST_STD_VER < 23
 ASSERT_NOEXCEPT(std::ranges::crbegin(std::declval<int (&)[10]>()));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowMemberRBegin {
   ThrowingIterator<int> rbegin() const noexcept; // auto(t.rbegin()) doesn't throw
 } ntmb;
 static_assert(noexcept(std::ranges::rbegin(ntmb)));
+#if TEST_STD_VER < 23
 static_assert(noexcept(std::ranges::crbegin(ntmb)));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowADLRBegin {
   friend ThrowingIterator<int> rbegin(NoThrowADLRBegin&) noexcept;  // auto(rbegin(t)) doesn't throw
   friend ThrowingIterator<int> rbegin(const NoThrowADLRBegin&) noexcept;
 } ntab;
 static_assert(noexcept(std::ranges::rbegin(ntab)));
+#if TEST_STD_VER < 23
 static_assert(noexcept(std::ranges::crbegin(ntab)));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowMemberRBeginReturnsRef {
   ThrowingIterator<int>& rbegin() const noexcept; // auto(t.rbegin()) may throw
 } ntmbrr;
 static_assert(!noexcept(std::ranges::rbegin(ntmbrr)));
+#if TEST_STD_VER < 23
 static_assert(!noexcept(std::ranges::crbegin(ntmbrr)));
+#endif // TEST_STD_VER < 23
 
 struct RBeginReturnsArrayRef {
     auto rbegin() const noexcept -> int(&)[10];
 } brar;
 static_assert(noexcept(std::ranges::rbegin(brar)));
+#if TEST_STD_VER < 23
 static_assert(noexcept(std::ranges::crbegin(brar)));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowBeginThrowingEnd {
   int* begin() const noexcept;
   int* end() const;
 } ntbte;
 static_assert(!noexcept(std::ranges::rbegin(ntbte)));
+#if TEST_STD_VER < 23
 static_assert(!noexcept(std::ranges::crbegin(ntbte)));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowEndThrowingBegin {
   int* begin() const;
   int* end() const noexcept;
 } ntetb;
 static_assert(noexcept(std::ranges::rbegin(ntetb)));
+#if TEST_STD_VER < 23
 static_assert(noexcept(std::ranges::crbegin(ntetb)));
+#endif // TEST_STD_VER < 23
 
 // Test ADL-proofing.
 struct Incomplete;
 template<class T> struct Holder { T t; };
 static_assert(!std::is_invocable_v<RangeRBeginT, Holder<Incomplete>*>);
 static_assert(!std::is_invocable_v<RangeRBeginT, Holder<Incomplete>*&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCRBeginT, Holder<Incomplete>*>);
 static_assert(!std::is_invocable_v<RangeCRBeginT, Holder<Incomplete>*&>);
+#endif // TEST_STD_VER < 23
 
 int main(int, char**) {
   static_assert(testReturnTypes());
diff --git a/libcxx/test/std/ranges/range.access/rend.pass.cpp b/libcxx/test/std/ranges/range.access/rend.pass.cpp
index f5f59edf19393f..adb150461e044b 100644
--- a/libcxx/test/std/ranges/range.access/rend.pass.cpp
+++ b/libcxx/test/std/ranges/range.access/rend.pass.cpp
@@ -9,7 +9,7 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 
 // std::ranges::rend
-// std::ranges::crend
+// std::ranges::crend // before C++23
 
 #include <ranges>
 
@@ -19,7 +19,9 @@
 #include "test_iterators.h"
 
 using RangeREndT = decltype(std::ranges::rend);
+#if TEST_STD_VER < 23
 using RangeCREndT = decltype(std::ranges::crend);
+#endif // TEST_STD_VER < 23
 
 static int globalBuff[8];
 
@@ -27,16 +29,20 @@ static_assert(!std::is_invocable_v<RangeREndT, int (&&)[]>);
 static_assert(!std::is_invocable_v<RangeREndT, int (&)[]>);
 static_assert(!std::is_invocable_v<RangeREndT, int (&&)[10]>);
 static_assert( std::is_invocable_v<RangeREndT, int (&)[10]>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCREndT, int (&&)[]>);
 static_assert(!std::is_invocable_v<RangeCREndT, int (&)[]>);
 static_assert(!std::is_invocable_v<RangeCREndT, int (&&)[10]>);
 static_assert( std::is_invocable_v<RangeCREndT, int (&)[10]>);
+#endif // TEST_STD_VER < 23
 
 struct Incomplete;
 static_assert(!std::is_invocable_v<RangeREndT, Incomplete(&&)[]>);
 static_assert(!std::is_invocable_v<RangeREndT, Incomplete(&&)[42]>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCREndT, Incomplete(&&)[]>);
 static_assert(!std::is_invocable_v<RangeCREndT, Incomplete(&&)[42]>);
+#endif // TEST_STD_VER < 23
 
 struct REndMember {
   int x;
@@ -49,50 +55,50 @@ static_assert( std::is_invocable_v<RangeREndT, REndMember&>);
 static_assert(!std::is_invocable_v<RangeREndT, REndMember &&>);
 static_assert( std::is_invocable_v<RangeREndT, REndMember const&>);
 static_assert(!std::is_invocable_v<RangeREndT, REndMember const&&>);
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCREndT, REndMember &>);
 static_assert(!std::is_invocable_v<RangeCREndT, REndMember &&>);
 static_assert( std::is_invocable_v<RangeCREndT, REndMember const&>);
 static_assert(!std::is_invocable_v<RangeCREndT, REndMember const&&>);
+#endif // TEST_STD_VER < 23
 
 constexpr bool testReturnTypes() {
-  {
-    int *x[2];
-    ASSERT_SAME_TYPE(decltype(std::ranges::rend(x)), std::reverse_iterator<int**>);
-    ASSERT_SAME_TYPE(decltype(std::ranges::crend(x)), std::reverse_iterator<int* const*>);
-  }
-
-  {
-    int x[2][2];
-    ASSERT_SAME_TYPE(decltype(std::ranges::rend(x)), std::reverse_iterator<int(*)[2]>);
-    ASSERT_SAME_TYPE(decltype(std::ranges::crend(x)), std::reverse_iterator<const int(*)[2]>);
-  }
-
-  {
-    struct Different {
-      char* rbegin();
-      sentinel_wrapper<char*>& rend();
-      short* rbegin() const;
-      sentinel_wrapper<short*>& rend() const;
-    } x;
-    ASSERT_SAME_TYPE(decltype(std::ranges::rend(x)), sentinel_wrapper<char*>);
-    ASSERT_SAME_TYPE(decltype(std::ranges::crend(x)), sentinel_wrapper<short*>);
-  }
+  int* a[2];
+  int b[2][2];
+  struct Different {
+    char* rbegin();
+    sentinel_wrapper<char*>& rend();
+    short* rbegin() const;
+    sentinel_wrapper<short*>& rend() const;
+  } c;
+
+  ASSERT_SAME_TYPE(decltype(std::ranges::rend(a)), std::reverse_iterator<int**>);
+  ASSERT_SAME_TYPE(decltype(std::ranges::rend(b)), std::reverse_iterator<int(*)[2]>);
+  ASSERT_SAME_TYPE(decltype(std::ranges::rend(c)), sentinel_wrapper<char*>);
+
+#if TEST_STD_VER < 23
+  ASSERT_SAME_TYPE(decltype(std::ranges::crend(a)), std::reverse_iterator<int* const*>);
+  ASSERT_SAME_TYPE(decltype(std::ranges::crend(b)), std::reverse_iterator<const int(*)[2]>);
+  ASSERT_SAME_TYPE(decltype(std::ranges::crend(c)), sentinel_wrapper<short*>);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
 
 constexpr bool testArray() {
   int a[2];
-  assert(std::ranges::rend(a).base() == a);
-  assert(std::ranges::crend(a).base() == a);
-
   int b[2][2];
-  assert(std::ranges::rend(b).base() == b);
-  assert(std::ranges::crend(b).base() == b);
-
   REndMember c[2];
+
+  assert(std::ranges::rend(a).base() == a);
+  assert(std::ranges::rend(b).base() == b);
   assert(std::ranges::rend(c).base() == c);
+
+#if TEST_STD_VER < 23
+  assert(std::ranges::crend(b).base() == b);
+  assert(std::ranges::crend(a).base() == a);
   assert(std::ranges::crend(c).base() == c);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
@@ -130,8 +136,10 @@ struct NonConstREndMember {
 };
 static_assert( std::is_invocable_v<RangeREndT,  NonConstREndMember &>);
 static_assert(!std::is_invocable_v<RangeREndT,  NonConstREndMember const&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCREndT, NonConstREndMember &>);
 static_assert(!std::is_invocable_v<RangeCREndT, NonConstREndMember const&>);
+#endif // TEST_STD_VER < 23
 
 struct EnabledBorrowingREndMember {
   constexpr int* rbegin() const { return nullptr; }
@@ -163,24 +171,24 @@ struct EmptyPtrREndMember {
 
 constexpr bool testREndMember() {
   REndMember a;
-  assert(std::ranges::rend(a) == &a.x);
-  assert(std::ranges::crend(a) == &a.x);
-
   NonConstREndMember b;
-  assert(std::ranges::rend(b) == &b.x);
-  static_assert(!std::is_invocable_v<RangeCREndT, decltype((b))>);
-
   EnabledBorrowingREndMember c;
-  assert(std::ranges::rend(std::move(c)) == &globalBuff[0]);
-  assert(std::ranges::crend(std::move(c)) == &globalBuff[0]);
-
   REndMemberFunction d;
-  assert(std::ranges::rend(d) == &d.x);
-  assert(std::ranges::crend(d) == &d.x);
-
   EmptyPtrREndMember e;
+
+  assert(std::ranges::rend(a) == &a.x);
+  assert(std::ranges::rend(b) == &b.x);
+  assert(std::ranges::rend(std::move(c)) == &globalBuff[0]);
+  assert(std::ranges::rend(d) == &d.x);
   assert(std::ranges::rend(e) == &e.x);
+
+#if TEST_STD_VER < 23
+  assert(std::ranges::crend(a) == &a.x);
+  static_assert(!std::is_invocable_v<RangeCREndT, decltype((b))>);
+  assert(std::ranges::crend(std::move(c)) == &globalBuff[0]);
+  assert(std::ranges::crend(d) == &d.x);
   assert(std::ranges::crend(e) == &e.x);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
@@ -197,8 +205,10 @@ static_assert(!std::is_invocable_v<RangeREndT, REndFunction &&>);
 static_assert( std::is_invocable_v<RangeREndT,  REndFunction const&>);
 static_assert(!std::is_invocable_v<RangeREndT,  REndFunction &&>);
 static_assert(std::is_invocable_v<RangeREndT, REndFunction&>); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCREndT, REndFunction const&>);
 static_assert( std::is_invocable_v<RangeCREndT, REndFunction &>);
+#endif // TEST_STD_VER < 23
 
 struct REndFunctionReturnsInt {
   friend constexpr int rbegin(REndFunctionReturnsInt const&);
@@ -233,7 +243,9 @@ struct REndFunctionByValue {
   friend constexpr int* rbegin(REndFunctionByValue) { return nullptr; }
   friend constexpr int* rend(REndFunctionByValue) { return &globalBuff[1]; }
 };
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCREndT, REndFunctionByValue>);
+#endif // TEST_STD_VER < 23
 
 struct REndFunctionEnabledBorrowing {
   friend constexpr int* rbegin(REndFunctionEnabledBorrowing) { return nullptr; }
@@ -269,47 +281,45 @@ struct RBeginMemberEndFunction {
 
 constexpr bool testREndFunction() {
   const REndFunction a{};
-  assert(std::ranges::rend(a) == &a.x);
-  assert(std::ranges::crend(a) == &a.x);
   REndFunction aa{};
-  assert(std::ranges::rend(aa) == &aa.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
-  assert(std::ranges::crend(aa) == &aa.x);
-
   REndFunctionByValue b;
-  assert(std::ranges::rend(b) == &globalBuff[1]);
-  assert(std::ranges::crend(b) == &globalBuff[1]);
-
   REndFunctionEnabledBorrowing c;
-  assert(std::ranges::rend(std::move(c)) == &globalBuff[2]);
-  assert(std::ranges::crend(std::move(c)) == &globalBuff[2]);
-
   const REndFunctionReturnsEmptyPtr d{};
-  assert(std::ranges::rend(d) == &d.x);
-  assert(std::ranges::crend(d) == &d.x);
   REndFunctionReturnsEmptyPtr dd{};
-  assert(std::ranges::rend(dd) == &dd.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
-  assert(std::ranges::crend(dd) == &dd.x);
-
   const REndFunctionWithDataMember e{};
-  assert(std::ranges::rend(e) == &e.x);
-  assert(std::ranges::crend(e) == &e.x);
   REndFunctionWithDataMember ee{};
-  assert(std::ranges::rend(ee) == &ee.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
-  assert(std::ranges::crend(ee) == &ee.x);
-
   const REndFunctionWithPrivateEndMember f{};
-  assert(std::ranges::rend(f) == &f.y);
-  assert(std::ranges::crend(f) == &f.y);
   REndFunctionWithPrivateEndMember ff{};
-  assert(std::ranges::rend(ff) == &ff.y); // Ill-formed before P2602R2 Poison Pills are Too Toxic
-  assert(std::ranges::crend(ff) == &ff.y);
-
   const RBeginMemberEndFunction g{};
-  assert(std::ranges::rend(g) == &g.x);
-  assert(std::ranges::crend(g) == &g.x);
   RBeginMemberEndFunction gg{};
+
+  assert(std::ranges::rend(a) == &a.x);
+  assert(std::ranges::rend(aa) == &aa.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+  assert(std::ranges::rend(b) == &globalBuff[1]);
+  assert(std::ranges::rend(std::move(c)) == &globalBuff[2]);
+  assert(std::ranges::rend(d) == &d.x);
+  assert(std::ranges::rend(dd) == &dd.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+  assert(std::ranges::rend(e) == &e.x);
+  assert(std::ranges::rend(ee) == &ee.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+  assert(std::ranges::rend(f) == &f.y);
+  assert(std::ranges::rend(ff) == &ff.y); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+  assert(std::ranges::rend(g) == &g.x);
   assert(std::ranges::rend(gg) == &gg.x); // Ill-formed before P2602R2 Poison Pills are Too Toxic
+
+#if TEST_STD_VER < 23
+  assert(std::ranges::crend(a) == &a.x);
+  assert(std::ranges::crend(aa) == &aa.x);
+  assert(std::ranges::crend(b) == &globalBuff[1]);
+  assert(std::ranges::crend(std::move(c)) == &globalBuff[2]);
+  assert(std::ranges::crend(d) == &d.x);
+  assert(std::ranges::crend(dd) == &dd.x);
+  assert(std::ranges::crend(e) == &e.x);
+  assert(std::ranges::crend(ee) == &ee.x);
+  assert(std::ranges::crend(f) == &f.y);
+  assert(std::ranges::crend(ff) == &ff.y);
+  assert(std::ranges::crend(g) == &g.x);
   assert(std::ranges::crend(gg) == &gg.x);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
@@ -325,7 +335,9 @@ struct MemberBeginEnd {
 };
 static_assert( std::is_invocable_v<RangeREndT, MemberBeginEnd&>);
 static_assert( std::is_invocable_v<RangeREndT, MemberBeginEnd const&>);
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCREndT, MemberBeginEnd const&>);
+#endif // TEST_STD_VER < 23
 
 struct FunctionBeginEnd {
   int b, e;
@@ -343,7 +355,9 @@ struct FunctionBeginEnd {
 };
 static_assert( std::is_invocable_v<RangeREndT, FunctionBeginEnd&>);
 static_assert( std::is_invocable_v<RangeREndT, FunctionBeginEnd const&>);
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCREndT, FunctionBeginEnd const&>);
+#endif // TEST_STD_VER < 23
 
 struct MemberBeginFunctionEnd {
   int b, e;
@@ -359,7 +373,9 @@ struct MemberBeginFunctionEnd {
 };
 static_assert( std::is_invocable_v<RangeREndT, MemberBeginFunctionEnd&>);
 static_assert( std::is_invocable_v<RangeREndT, MemberBeginFunctionEnd const&>);
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCREndT, MemberBeginFunctionEnd const&>);
+#endif // TEST_STD_VER < 23
 
 struct FunctionBeginMemberEnd {
   int b, e;
@@ -375,59 +391,77 @@ struct FunctionBeginMemberEnd {
 };
 static_assert( std::is_invocable_v<RangeREndT, FunctionBeginMemberEnd&>);
 static_assert( std::is_invocable_v<RangeREndT, FunctionBeginMemberEnd const&>);
+#if TEST_STD_VER < 23
 static_assert( std::is_invocable_v<RangeCREndT, FunctionBeginMemberEnd const&>);
+#endif // TEST_STD_VER < 23
 
 struct MemberBeginEndDifferentTypes {
   bidirectional_iterator<int*> begin();
   bidirectional_iterator<const int*> end();
 };
 static_assert(!std::is_invocable_v<RangeREndT, MemberBeginEndDifferentTypes&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCREndT, MemberBeginEndDifferentTypes&>);
+#endif // TEST_STD_VER < 23
 
 struct FunctionBeginEndDifferentTypes {
   friend bidirectional_iterator<int*> begin(FunctionBeginEndDifferentTypes&);
   friend bidirectional_iterator<const int*> end(FunctionBeginEndDifferentTypes&);
 };
 static_assert(!std::is_invocable_v<RangeREndT, FunctionBeginEndDifferentTypes&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCREndT, FunctionBeginEndDifferentTypes&>);
+#endif // TEST_STD_VER < 23
 
 struct MemberBeginEndForwardIterators {
   forward_iterator<int*> begin();
   forward_iterator<int*> end();
 };
 static_assert(!std::is_invocable_v<RangeREndT, MemberBeginEndForwardIterators&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCREndT, MemberBeginEndForwardIterators&>);
+#endif // TEST_STD_VER < 23
 
 struct FunctionBeginEndForwardIterators {
   friend forward_iterator<int*> begin(FunctionBeginEndForwardIterators&);
   friend forward_iterator<int*> end(FunctionBeginEndForwardIterators&);
 };
 static_assert(!std::is_invocable_v<RangeREndT, FunctionBeginEndForwardIterators&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCREndT, FunctionBeginEndForwardIterators&>);
+#endif // TEST_STD_VER < 23
 
 struct MemberBeginOnly {
   bidirectional_iterator<int*> begin() const;
 };
 static_assert(!std::is_invocable_v<RangeREndT, MemberBeginOnly&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCREndT, MemberBeginOnly&>);
+#endif // TEST_STD_VER < 23
 
 struct FunctionBeginOnly {
   friend bidirectional_iterator<int*> begin(FunctionBeginOnly&);
 };
 static_assert(!std::is_invocable_v<RangeREndT, FunctionBeginOnly&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCREndT, FunctionBeginOnly&>);
+#endif // TEST_STD_VER < 23
 
 struct MemberEndOnly {
   bidirectional_iterator<int*> end() const;
 };
 static_assert(!std::is_invocable_v<RangeREndT, MemberEndOnly&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCREndT, MemberEndOnly&>);
+#endif // TEST_STD_VER < 23
 
 struct FunctionEndOnly {
   friend bidirectional_iterator<int*> end(FunctionEndOnly&);
 };
 static_assert(!std::is_invocable_v<RangeREndT, FunctionEndOnly&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCREndT, FunctionEndOnly&>);
+#endif // TEST_STD_VER < 23
 
 // Make sure there is no clash between the following cases:
 // - the case that handles classes defining member `rbegin` and `rend` functions;
@@ -438,53 +472,60 @@ struct MemberBeginAndRBegin {
   int* rbegin() const;
   int* rend() const;
 };
-static_assert( std::is_invocable_v<RangeREndT, MemberBeginAndRBegin&>);
-static_assert( std::is_invocable_v<RangeCREndT, MemberBeginAndRBegin&>);
+static_assert(std::is_invocable_v<RangeREndT, MemberBeginAndRBegin&>);
 static_assert( std::same_as<std::invoke_result_t<RangeREndT, MemberBeginAndRBegin&>, int*>);
+#if TEST_STD_VER < 23
+static_assert(std::is_invocable_v<RangeCREndT, MemberBeginAndRBegin&>);
 static_assert( std::same_as<std::invoke_result_t<RangeCREndT, MemberBeginAndRBegin&>, int*>);
+#endif // TEST_STD_VER < 23
 
 constexpr bool testBeginEnd() {
   MemberBeginEnd a{};
   const MemberBeginEnd aa{};
-  assert(base(std::ranges::rend(a).base()) == &a.b);
-  assert(base(std::ranges::crend(a).base()) == &a.cb);
-  assert(base(std::ranges::rend(aa).base()) == &aa.cb);
-  assert(base(std::ranges::crend(aa).base()) == &aa.cb);
-
   FunctionBeginEnd b{};
   const FunctionBeginEnd bb{};
-  assert(base(std::ranges::rend(b).base()) == &b.b);
-  assert(base(std::ranges::crend(b).base()) == &b.cb);
-  assert(base(std::ranges::rend(bb).base()) == &bb.cb);
-  assert(base(std::ranges::crend(bb).base()) == &bb.cb);
-
   MemberBeginFunctionEnd c{};
   const MemberBeginFunctionEnd cc{};
-  assert(base(std::ranges::rend(c).base()) == &c.b);
-  assert(base(std::ranges::crend(c).base()) == &c.cb);
-  assert(base(std::ranges::rend(cc).base()) == &cc.cb);
-  assert(base(std::ranges::crend(cc).base()) == &cc.cb);
-
   FunctionBeginMemberEnd d{};
   const FunctionBeginMemberEnd dd{};
+
+  assert(base(std::ranges::rend(a).base()) == &a.b);
+  assert(base(std::ranges::rend(aa).base()) == &aa.cb);
+  assert(base(std::ranges::rend(b).base()) == &b.b);
+  assert(base(std::ranges::rend(bb).base()) == &bb.cb);
+  assert(base(std::ranges::rend(c).base()) == &c.b);
+  assert(base(std::ranges::rend(cc).base()) == &cc.cb);
   assert(base(std::ranges::rend(d).base()) == &d.b);
-  assert(base(std::ranges::crend(d).base()) == &d.cb);
   assert(base(std::ranges::rend(dd).base()) == &dd.cb);
+
+#if TEST_STD_VER < 23
+  assert(base(std::ranges::crend(a).base()) == &a.cb);
+  assert(base(std::ranges::crend(aa).base()) == &aa.cb);
+  assert(base(std::ranges::crend(b).base()) == &b.cb);
+  assert(base(std::ranges::crend(bb).base()) == &bb.cb);
+  assert(base(std::ranges::crend(c).base()) == &c.cb);
+  assert(base(std::ranges::crend(cc).base()) == &cc.cb);
+  assert(base(std::ranges::crend(d).base()) == &d.cb);
   assert(base(std::ranges::crend(dd).base()) == &dd.cb);
+#endif // TEST_STD_VER < 23
 
   return true;
 }
 
 
 ASSERT_NOEXCEPT(std::ranges::rend(std::declval<int (&)[10]>()));
+#if TEST_STD_VER < 23
 ASSERT_NOEXCEPT(std::ranges::crend(std::declval<int (&)[10]>()));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowMemberREnd {
   ThrowingIterator<int> rbegin() const;
   ThrowingIterator<int> rend() const noexcept; // auto(t.rend()) doesn't throw
 } ntmre;
 static_assert(noexcept(std::ranges::rend(ntmre)));
+#if TEST_STD_VER < 23
 static_assert(noexcept(std::ranges::crend(ntmre)));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowADLREnd {
   ThrowingIterator<int> rbegin() const;
@@ -492,43 +533,55 @@ struct NoThrowADLREnd {
   friend ThrowingIterator<int> rend(const NoThrowADLREnd&) noexcept;
 } ntare;
 static_assert(noexcept(std::ranges::rend(ntare)));
+#if TEST_STD_VER < 23
 static_assert(noexcept(std::ranges::crend(ntare)));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowMemberREndReturnsRef {
   ThrowingIterator<int> rbegin() const;
   ThrowingIterator<int>& rend() const noexcept; // auto(t.rend()) may throw
 } ntmrerr;
 static_assert(!noexcept(std::ranges::rend(ntmrerr)));
+#if TEST_STD_VER < 23
 static_assert(!noexcept(std::ranges::crend(ntmrerr)));
+#endif // TEST_STD_VER < 23
 
 struct REndReturnsArrayRef {
     auto rbegin() const noexcept -> int(&)[10];
     auto rend() const noexcept -> int(&)[10];
 } rerar;
 static_assert(noexcept(std::ranges::rend(rerar)));
+#if TEST_STD_VER < 23
 static_assert(noexcept(std::ranges::crend(rerar)));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowBeginThrowingEnd {
   int* begin() const noexcept;
   int* end() const;
 } ntbte;
 static_assert(noexcept(std::ranges::rend(ntbte)));
+#if TEST_STD_VER < 23
 static_assert(noexcept(std::ranges::crend(ntbte)));
+#endif // TEST_STD_VER < 23
 
 struct NoThrowEndThrowingBegin {
   int* begin() const;
   int* end() const noexcept;
 } ntetb;
 static_assert(!noexcept(std::ranges::rend(ntetb)));
+#if TEST_STD_VER < 23
 static_assert(!noexcept(std::ranges::crend(ntetb)));
+#endif // TEST_STD_VER < 23
 
 // Test ADL-proofing.
 struct Incomplete;
 template<class T> struct Holder { T t; };
 static_assert(!std::is_invocable_v<RangeREndT, Holder<Incomplete>*>);
 static_assert(!std::is_invocable_v<RangeREndT, Holder<Incomplete>*&>);
+#if TEST_STD_VER < 23
 static_assert(!std::is_invocable_v<RangeCREndT, Holder<Incomplete>*>);
 static_assert(!std::is_invocable_v<RangeCREndT, Holder<Incomplete>*&>);
+#endif // TEST_STD_VER < 23
 
 int main(int, char**) {
   static_assert(testReturnTypes());
diff --git a/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp b/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
index 3f7c174d3fe48a..8c711cd7708622 100644
--- a/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
+++ b/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
@@ -35,8 +35,15 @@ using InputIter = cpp20_input_iterator<const int*>;
 
 struct InputRange : std::ranges::view_interface<InputRange> {
   int buff[8] = {0, 1, 2, 3, 4, 5, 6, 7};
+
   constexpr InputIter begin() const { return InputIter(buff); }
-  constexpr InputIter end() const { return InputIter(buff + 8); }
+  constexpr sentinel_wrapper<InputIter> end() const { return sentinel_wrapper(InputIter(buff + 8)); }
+};
+
+struct NonConstInputRange : std::ranges::view_interface<NonConstInputRange> {
+  int buff[8] = {0, 1, 2, 3, 4, 5, 6, 7};
+  constexpr InputIter begin() { return InputIter(buff); }
+  constexpr sentinel_wrapper<InputIter> end() { return sentinel_wrapper(InputIter(buff + 8)); }
 };
 
 struct SizedInputRange : std::ranges::view_interface<SizedInputRange> {
@@ -222,6 +229,19 @@ constexpr bool testEmpty() {
   return true;
 }
 
+#if TEST_STD_VER >= 23
+template <class T>
+concept ConstAccessorsInvocable = requires(T& t) {
+  t.cbegin();
+  t.cend();
+};
+
+static_assert(ConstAccessorsInvocable<InputRange>);
+static_assert(ConstAccessorsInvocable<const InputRange>);
+static_assert(ConstAccessorsInvocable<NonConstInputRange>);
+static_assert(!ConstAccessorsInvocable<const NonConstInputRange>);
+#endif // TEST_STD_VER >= 23
+
 template<class T>
 concept DataInvocable = requires (T const& obj) { obj.data(); };
 
diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py
index 3bdd3adad15b4e..e2ab4cad559a0e 100755
--- a/libcxx/utils/generate_feature_test_macro_components.py
+++ b/libcxx/utils/generate_feature_test_macro_components.py
@@ -1001,8 +1001,7 @@ def add_version_header(tc):
         {
             "name": "__cpp_lib_ranges_as_const",
             "values": {
-                "c++23": 202207  # P2278R4 cbegin should always return a constant iterator
-                #        202311  # DR P2836R1 std::basic_const_iterator should follow its underlying type’s convertibility
+                "c++23": 202311  # DR P2836R1 std::basic_const_iterator should follow its underlying type’s convertibility
             },
             "headers": ["ranges"],
             "unimplemented": True,



More information about the libcxx-commits mailing list