[libcxx-commits] [libcxx] [libcxx] applies integer-like changes from [P2393R1] (PR #74161)
Christopher Di Bella via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Dec 13 12:19:53 PST 2023
https://github.com/cjdb updated https://github.com/llvm/llvm-project/pull/74161
>From 48f58fcbd559519e88d14cd8def3bc1331468b04 Mon Sep 17 00:00:00 2001
From: Christopher Di Bella <cjdb at google.com>
Date: Fri, 1 Dec 2023 23:30:06 +0000
Subject: [PATCH 1/2] [libcxx] applies integer-like changes from [P2393R1]
libc++ is already conforming with this paper since its _integer-like_
types are extended integral types. Given that Clang supports `_BitInt`
as a C++ extension, there isn't a need to support class-types' potential
explicit conversion requriements.
We still do so, however, because software development is malleable.
These changes don't impact codegen or correctness, and this will add
resilience to change if the above paragraph ultimately proves false.
[P2393R1]: http://wg21.link/p2393r1
---
libcxx/docs/Status/Cxx23Papers.csv | 2 +-
libcxx/include/__ranges/counted.h | 13 +++++++------
libcxx/include/__ranges/subrange.h | 13 +++++--------
libcxx/include/__ranges/take_view.h | 8 ++++----
4 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/libcxx/docs/Status/Cxx23Papers.csv b/libcxx/docs/Status/Cxx23Papers.csv
index b4f915d37d0021..c72d64e4220d0d 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 882f90b1ed82e7..ba83543ab4a3eb 100644
--- a/libcxx/include/__ranges/counted.h
+++ b/libcxx/include/__ranges/counted.h
@@ -38,12 +38,13 @@ namespace ranges::views {
namespace __counted {
struct __fn {
- template<contiguous_iterator _It>
- _LIBCPP_HIDE_FROM_ABI
- static constexpr auto __go(_It __it, iter_difference_t<_It> __count)
- noexcept(noexcept(span(std::to_address(__it), static_cast<size_t>(__count))))
- // Deliberately omit return-type SFINAE, because to_address is not SFINAE-friendly
- { return span(std::to_address(__it), static_cast<size_t>(__count)); }
+ template <contiguous_iterator _It>
+ _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_It __it, iter_difference_t<_It> __count) noexcept(
+ noexcept(span(std::to_address(__it), static_cast<size_t>(static_cast<iter_difference_t<_It>>(__count)))))
+ // Deliberately omit return-type SFINAE, because to_address is not SFINAE-friendly
+ {
+ return span(std::to_address(__it), static_cast<size_t>(static_cast<iter_difference_t<_It>>(__count)));
+ }
template<random_access_iterator _It>
_LIBCPP_HIDE_FROM_ABI
diff --git a/libcxx/include/__ranges/subrange.h b/libcxx/include/__ranges/subrange.h
index 75f9284a582ff1..1bc41a75e2128f 100644
--- a/libcxx/include/__ranges/subrange.h
+++ b/libcxx/include/__ranges/subrange.h
@@ -122,15 +122,12 @@ namespace ranges {
: subrange(ranges::begin(__range), ranges::end(__range))
{ }
- template<__different_from<subrange> _Range>
- requires borrowed_range<_Range> &&
- __convertible_to_non_slicing<iterator_t<_Range>, _Iter> &&
+ template <__different_from<subrange> _Range>
+ requires borrowed_range<_Range> && __convertible_to_non_slicing<iterator_t<_Range>, _Iter> &&
convertible_to<sentinel_t<_Range>, _Sent>
- _LIBCPP_HIDE_FROM_ABI
- constexpr subrange(_Range&& __range)
- requires _StoreSize && sized_range<_Range>
- : subrange(__range, ranges::size(__range))
- { }
+ _LIBCPP_HIDE_FROM_ABI constexpr subrange(_Range&& __range)
+ requires _StoreSize && sized_range<_Range>
+ : subrange(__range, static_cast<decltype(__size_)>(ranges::size(__range))) {}
template<borrowed_range _Range>
requires __convertible_to_non_slicing<iterator_t<_Range>, _Iter> &&
diff --git a/libcxx/include/__ranges/take_view.h b/libcxx/include/__ranges/take_view.h
index 518375d684abdd..229ba72ced31ca 100644
--- a/libcxx/include/__ranges/take_view.h
+++ b/libcxx/include/__ranges/take_view.h
@@ -87,7 +87,7 @@ class take_view : public view_interface<take_view<_View>> {
return ranges::begin(__base_);
} else {
using _DifferenceT = range_difference_t<_View>;
- auto __size = size();
+ auto __size = range_difference_t<_View>(size());
return counted_iterator(ranges::begin(__base_), static_cast<_DifferenceT>(__size));
}
} else {
@@ -102,7 +102,7 @@ class take_view : public view_interface<take_view<_View>> {
return ranges::begin(__base_);
} else {
using _DifferenceT = range_difference_t<const _View>;
- auto __size = size();
+ auto __size = range_difference_t<_View>(size());
return counted_iterator(ranges::begin(__base_), static_cast<_DifferenceT>(__size));
}
} else {
@@ -114,7 +114,7 @@ class take_view : public view_interface<take_view<_View>> {
constexpr auto end() requires (!__simple_view<_View>) {
if constexpr (sized_range<_View>) {
if constexpr (random_access_range<_View>) {
- return ranges::begin(__base_) + size();
+ return ranges::begin(__base_) + range_difference_t<_View>(size());
} else {
return default_sentinel;
}
@@ -127,7 +127,7 @@ class take_view : public view_interface<take_view<_View>> {
constexpr auto end() const requires range<const _View> {
if constexpr (sized_range<const _View>) {
if constexpr (random_access_range<const _View>) {
- return ranges::begin(__base_) + size();
+ return ranges::begin(__base_) + range_difference_t<_View>(size());
} else {
return default_sentinel;
}
>From 44a02f11dd09d8ddd92369c03f2c7fdf09b1e4f4 Mon Sep 17 00:00:00 2001
From: Christopher Di Bella <cjdb at google.com>
Date: Wed, 13 Dec 2023 20:15:49 +0000
Subject: [PATCH 2/2] adds test for `__int128` and `_BitInt(N)`
---
.../iterator.concepts/incrementable.h | 10 ++
.../weakly_incrementable.compile.pass.cpp | 132 ++++++++++++++++++
2 files changed, 142 insertions(+)
diff --git a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/incrementable.h b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/incrementable.h
index 16eddd6f06e693..16e7bf040c646b 100644
--- a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/incrementable.h
+++ b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/incrementable.h
@@ -9,6 +9,8 @@
#ifndef LIBCPP_TEST_STD_ITERATORS_ITERATOR_REQUIREMENTS_ITERATOR_CONCEPTS_INCREMENTABLE_H
#define LIBCPP_TEST_STD_ITERATORS_ITERATOR_REQUIREMENTS_ITERATOR_CONCEPTS_INCREMENTABLE_H
+#include <concepts>
+
struct postfix_increment_returns_void {
using difference_type = int;
postfix_increment_returns_void& operator++();
@@ -181,4 +183,12 @@ struct noncopyable_with_difference_type_and_minus {
bool operator==(noncopyable_with_difference_type_and_minus const&) const;
};
+template <std::signed_integral T>
+struct extended_integral_difference_type {
+ using difference_type = T;
+
+ extended_integral_difference_type& operator++();
+ void operator++(int);
+};
+
#endif // #define LIBCPP_TEST_STD_ITERATORS_ITERATOR_REQUIREMENTS_ITERATOR_CONCEPTS_INCREMENTABLE_H
diff --git a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.winc/weakly_incrementable.compile.pass.cpp b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.winc/weakly_incrementable.compile.pass.cpp
index 22b3ae94e5fc39..c37c6d7e6e707a 100644
--- a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.winc/weakly_incrementable.compile.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.winc/weakly_incrementable.compile.pass.cpp
@@ -18,6 +18,7 @@
#include <optional>
#include "../incrementable.h"
+#include "test_macros.h"
static_assert(std::weakly_incrementable<int>);
static_assert(std::weakly_incrementable<int*>);
@@ -67,3 +68,134 @@ static_assert(std::weakly_incrementable<difference_type_and_void_minus>);
static_assert(std::weakly_incrementable<noncopyable_with_difference_type>);
static_assert(std::weakly_incrementable<noncopyable_without_difference_type>);
static_assert(std::weakly_incrementable<noncopyable_with_difference_type_and_minus>);
+
+#if !defined(TEST_HAS_NO_INT128)
+static_assert(std::weakly_incrementable<extended_integral_difference_type<__int128>>);
+#endif
+
+#if defined(__BIT_TYPES_DEFINED__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wbit-int-extension"
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(8)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(9)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(10)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(11)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(12)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(13)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(14)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(15)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(16)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(17)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(18)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(19)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(20)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(21)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(22)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(23)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(24)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(25)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(26)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(27)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(28)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(29)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(30)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(31)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(32)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(33)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(34)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(35)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(36)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(37)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(38)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(39)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(40)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(41)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(42)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(43)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(44)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(45)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(46)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(47)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(48)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(49)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(50)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(51)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(52)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(53)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(54)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(55)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(56)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(57)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(58)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(59)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(60)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(61)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(62)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(63)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(64)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(65)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(66)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(67)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(68)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(69)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(70)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(71)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(72)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(73)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(74)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(75)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(76)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(77)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(78)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(79)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(80)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(81)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(82)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(83)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(84)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(85)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(86)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(87)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(88)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(89)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(90)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(91)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(92)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(93)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(94)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(95)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(96)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(97)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(98)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(99)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(100)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(101)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(102)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(103)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(104)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(105)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(106)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(107)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(108)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(109)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(110)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(111)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(112)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(113)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(114)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(115)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(116)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(117)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(118)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(119)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(120)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(121)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(122)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(123)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(124)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(125)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(126)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(127)>>);
+static_assert(std::weakly_incrementable<extended_integral_difference_type<_BitInt(128)>>);
+# pragma GCC diagnostic pop
+#endif
More information about the libcxx-commits
mailing list