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

Christopher Di Bella via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 1 16:31:39 PST 2023


https://github.com/cjdb created https://github.com/llvm/llvm-project/pull/74161

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

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

[P2393R1]: http://wg21.link/p2393r1

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

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

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

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

diff --git a/libcxx/docs/Status/Cxx23Papers.csv b/libcxx/docs/Status/Cxx23Papers.csv
index 5cc9e488297b9f7..1fceeacc589cf63 100644
--- a/libcxx/docs/Status/Cxx23Papers.csv
+++ b/libcxx/docs/Status/Cxx23Papers.csv
@@ -35,7 +35,7 @@
 "`P2301R1 <https://wg21.link/P2301R1>`__","LWG","Add a ``pmr`` alias for ``std::stacktrace``","October 2021","",""
 "`P2321R2 <https://wg21.link/P2321R2>`__","LWG","``zip``","October 2021","|In Progress|","","|ranges|"
 "`P2340R1 <https://wg21.link/P2340R1>`__","LWG","Clarifying the status of the 'C headers'","October 2021","",""
-"`P2393R1 <https://wg21.link/P2393R1>`__","LWG","Cleaning up ``integer``-class types","October 2021","",""
+"`P2393R1 <https://wg21.link/P2393R1>`__","LWG","Cleaning up ``integer``-class types","October 2021","|Complete|","18.0"
 "`P2401R0 <https://wg21.link/P2401R0>`__","LWG","Add a conditional ``noexcept`` specification to ``std::exchange``","October 2021","|Complete|","14.0"
 "","","","","","",""
 "`P0323R12 <https://wg21.link/P0323R12>`__","LWG","``std::expected``","February 2022","|Complete|","16.0"
diff --git a/libcxx/include/__ranges/counted.h b/libcxx/include/__ranges/counted.h
index 882f90b1ed82e7c..d7e967c7627dee6 100644
--- a/libcxx/include/__ranges/counted.h
+++ b/libcxx/include/__ranges/counted.h
@@ -41,9 +41,9 @@ namespace __counted {
     template<contiguous_iterator _It>
     _LIBCPP_HIDE_FROM_ABI
     static constexpr auto __go(_It __it, iter_difference_t<_It> __count)
-      noexcept(noexcept(span(std::to_address(__it), static_cast<size_t>(__count))))
+      noexcept(noexcept(span(std::to_address(__it), static_cast<size_t>(static_cast<iter_difference_t<_It>>(__count)))))
       // Deliberately omit return-type SFINAE, because to_address is not SFINAE-friendly
-      { return          span(std::to_address(__it), static_cast<size_t>(__count)); }
+      { return          span(std::to_address(__it), static_cast<size_t>(static_cast<iter_difference_t<_It>>(__count))); }
 
     template<random_access_iterator _It>
     _LIBCPP_HIDE_FROM_ABI
diff --git a/libcxx/include/__ranges/subrange.h b/libcxx/include/__ranges/subrange.h
index 75f9284a582ff1a..0413f1821678750 100644
--- a/libcxx/include/__ranges/subrange.h
+++ b/libcxx/include/__ranges/subrange.h
@@ -129,7 +129,7 @@ namespace ranges {
     _LIBCPP_HIDE_FROM_ABI
     constexpr subrange(_Range&& __range)
       requires _StoreSize && sized_range<_Range>
-      : subrange(__range, ranges::size(__range))
+      : subrange(__range, static_cast<decltype(__size_)>(ranges::size(__range)))
     { }
 
     template<borrowed_range _Range>
diff --git a/libcxx/include/__ranges/take_view.h b/libcxx/include/__ranges/take_view.h
index 4204017d9249bcf..5331a0e3843dd91 100644
--- a/libcxx/include/__ranges/take_view.h
+++ b/libcxx/include/__ranges/take_view.h
@@ -87,7 +87,7 @@ class take_view : public view_interface<take_view<_View>> {
         return ranges::begin(__base_);
       } else {
         using _DifferenceT = range_difference_t<_View>;
-        auto __size = size();
+        auto __size = range_difference_t<_View>(size());
         return counted_iterator(ranges::begin(__base_), static_cast<_DifferenceT>(__size));
       }
     } else {
@@ -102,7 +102,7 @@ class take_view : public view_interface<take_view<_View>> {
         return ranges::begin(__base_);
       } else {
         using _DifferenceT = range_difference_t<const _View>;
-        auto __size = size();
+        auto __size = range_difference_t<_View>(size());
         return counted_iterator(ranges::begin(__base_), static_cast<_DifferenceT>(__size));
       }
     } else {
@@ -114,7 +114,7 @@ class take_view : public view_interface<take_view<_View>> {
   constexpr auto end() requires (!__simple_view<_View>) {
     if constexpr (sized_range<_View>) {
       if constexpr (random_access_range<_View>) {
-        return ranges::begin(__base_) + size();
+        return ranges::begin(__base_) + range_difference_t<_View>(size());
       } else {
         return default_sentinel;
       }
@@ -127,7 +127,7 @@ class take_view : public view_interface<take_view<_View>> {
   constexpr auto end() const requires range<const _View> {
     if constexpr (sized_range<const _View>) {
       if constexpr (random_access_range<const _View>) {
-        return ranges::begin(__base_) + size();
+        return ranges::begin(__base_) + range_difference_t<_View>(size());
       } else {
         return default_sentinel;
       }



More information about the libcxx-commits mailing list