From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1725) id DAEC43850408; Fri, 28 Aug 2020 19:54:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAEC43850408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598644459; bh=3kcNBCG1sAbNiMKJdBy0sHh95KnDEXGYDredVAcUcM4=; h=From:To:Subject:Date:From; b=qYKVKVPpfus5AR530zoXg3muOQtwhXk1vBW2xQYX/HTfkMZBA7dSZEw1p0GGS+uxX SXMxKeZasNzC6HOp6DIbxUNSlnN/1da+kJVRfNG+7NN0YKJvyrKIqArEVEgQdKq4iX pvicR8auF8IsjWhww9mvORX17xZ3KAUPzQhb5nFY= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: William Schmidt To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/users/wschmidt/heads/builtins3)] libstdc++: Make incrementable<__int128> satisfied in strict mode X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/users/wschmidt/heads/builtins3 X-Git-Oldrev: 300ef2fcc10e98359d14654be23bbb84a5d141e1 X-Git-Newrev: 5e9ad288eb6fb366142b166e7985d16727b398e1 Message-Id: <20200828195419.DAEC43850408@sourceware.org> Date: Fri, 28 Aug 2020 19:54:19 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Aug 2020 19:54:20 -0000 https://gcc.gnu.org/g:5e9ad288eb6fb366142b166e7985d16727b398e1 commit 5e9ad288eb6fb366142b166e7985d16727b398e1 Author: Jonathan Wakely Date: Thu Aug 20 19:41:15 2020 +0100 libstdc++: Make incrementable<__int128> satisfied in strict mode This adds specializations of std::incrementable_traits so that 128-bit integers are always considered incrementable (and therefore usable with std::ranges::iota_view) even when they don't satisfy std::integral. libstdc++-v3/ChangeLog: * include/bits/iterator_concepts.h [__STRICT_ANSI__] (incrementable_traits<__int128>): Define specialization. (incrementable_traits): Likewise. * testsuite/std/ranges/iota/96042.cc: Test iota_view with __int128. Diff: --- libstdc++-v3/include/bits/iterator_concepts.h | 11 ++++++++++ libstdc++-v3/testsuite/std/ranges/iota/96042.cc | 28 ++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/iterator_concepts.h b/libstdc++-v3/include/bits/iterator_concepts.h index 5033f2bddc3..bd6660c5f22 100644 --- a/libstdc++-v3/include/bits/iterator_concepts.h +++ b/libstdc++-v3/include/bits/iterator_concepts.h @@ -173,6 +173,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION = make_signed_t() - std::declval<_Tp>())>; }; +#if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__ + // __int128 is incrementable even if !integral<__int128> + template<> + struct incrementable_traits<__int128> + { using difference_type = __int128; }; + + template<> + struct incrementable_traits + { using difference_type = __int128; }; +#endif + namespace __detail { // An iterator such that iterator_traits<_Iter> names a specialization diff --git a/libstdc++-v3/testsuite/std/ranges/iota/96042.cc b/libstdc++-v3/testsuite/std/ranges/iota/96042.cc index 6f5c8f61fd2..911663bc413 100644 --- a/libstdc++-v3/testsuite/std/ranges/iota/96042.cc +++ b/libstdc++-v3/testsuite/std/ranges/iota/96042.cc @@ -24,8 +24,33 @@ void test01() { // PR libstdc++/96042 - using V = std::ranges::iota_view; + using V = std::ranges::iota_view; + + // In strict -std=c++20 mode there is no integer wider than long long, + // so V's difference type is an integer-class type, [iterator.concept.winc]. + // In practice this is either __int128 or __detail::__max_diff_type. using D = std::ranges::range_difference_t; + // Ensure that numeric_limits is correctly specialized for the type. + using L = std::numeric_limits; + static_assert( L::is_specialized ); + static_assert( L::is_signed ); + static_assert( L::is_integer ); + static_assert( L::is_exact ); + static_assert( L::digits > std::numeric_limits::digits ); + static_assert( L::digits10 == static_cast(L::digits * 0.30103) ); + static_assert( L::min() == (D(1) << L::digits) ); + static_assert( L::max() == ~L::min() ); + static_assert( L::lowest() == L::min() ); +} + +#ifdef __SIZEOF_INT128__ +void +test02() +{ + // When the target supports __int128 it can be used in iota_view + // even in strict mode where !integral<__int128>. + using V = std::ranges::iota_view<__int128, __int128>; + using D = std::ranges::range_difference_t; // __detail::__max_diff_type using L = std::numeric_limits; static_assert( L::is_specialized ); static_assert( L::is_signed ); @@ -37,3 +62,4 @@ test01() static_assert( L::max() == ~L::min() ); static_assert( L::lowest() == L::min() ); } +#endif