Skip to content

Commit ad31e11

Browse files
authored
[libc++] Make views::iota aware of __int128 (#167869)
Fixes #167991
1 parent 48dca1e commit ad31e11

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

libcxx/docs/ReleaseNotes/22.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,8 @@ ABI Affecting Changes
114114
potentially inheriting from the types they wrap. At this point in time we are not aware of any ABI changes caused by
115115
this.
116116

117+
- ``ranges::iota_view`` is now aware of ``__int128``. This causes ``iota_view::difference_type`` to change from
118+
``long long`` to ``__int128`` in some cases.
119+
117120
Build System Changes
118121
--------------------

libcxx/include/__ranges/iota_view.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ struct __get_wider_signed {
5858
return type_identity<int>{};
5959
else if constexpr (sizeof(_Int) < sizeof(long))
6060
return type_identity<long>{};
61-
else
61+
else if constexpr (sizeof(_Int) < sizeof(long long))
6262
return type_identity<long long>{};
63-
64-
static_assert(
65-
sizeof(_Int) <= sizeof(long long), "Found integer-like type that is bigger than largest integer like type.");
63+
# if _LIBCPP_HAS_INT128
64+
else if constexpr (sizeof(_Int) <= sizeof(__int128))
65+
return type_identity<__int128>{};
66+
# else
67+
else if constexpr (sizeof(_Int) <= sizeof(long long))
68+
return type_identity<long long>{};
69+
# endif
70+
else
71+
static_assert(false, "Found integer-like type that is bigger than the largest integer like type.");
6672
}
6773

6874
using type = typename decltype(__call())::type;

libcxx/test/std/ranges/range.factories/range.iota.view/indices.pass.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <vector>
2222

2323
#include "test_macros.h"
24-
#define TEST_HAS_NO_INT128 // Size cannot be larger than 64 bits
2524
#include "type_algorithms.h"
2625

2726
#include "types.h"

libcxx/test/std/ranges/range.factories/range.iota.view/iterator/member_typedefs.compile.pass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ void test() {
106106
// Same as below, if there is no type larger than long, we can just use that.
107107
static_assert(sizeof(Iter::difference_type) >= sizeof(long));
108108
static_assert(std::is_signed_v<Iter::difference_type>);
109+
#ifdef TEST_HAS_NO_INT128
109110
LIBCPP_STATIC_ASSERT(std::same_as<Iter::difference_type, long long>);
111+
#else
112+
LIBCPP_STATIC_ASSERT(std::same_as<Iter::difference_type,
113+
std::conditional_t<sizeof(long) == sizeof(long long), __int128, long long>>);
114+
#endif
110115
}
111116
{
112117
const std::ranges::iota_view<long long> io(0);
@@ -118,7 +123,11 @@ void test() {
118123
// https://eel.is/c++draft/range.iota.view#1.3
119124
static_assert(sizeof(Iter::difference_type) >= sizeof(long long));
120125
static_assert(std::is_signed_v<Iter::difference_type>);
126+
#ifdef TEST_HAS_NO_INT128
121127
LIBCPP_STATIC_ASSERT(std::same_as<Iter::difference_type, long long>);
128+
#else
129+
LIBCPP_STATIC_ASSERT(std::same_as<Iter::difference_type, __int128>);
130+
#endif
122131
}
123132
{
124133
const std::ranges::iota_view<Decrementable> io;

0 commit comments

Comments
 (0)