From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26464 invoked by alias); 15 Jan 2020 17:02:22 -0000 Mailing-List: contact libstdc++-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libstdc++-owner@gcc.gnu.org Received: (qmail 26435 invoked by uid 89); 15 Jan 2020 17:02:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=_Iterator, 34722, _iterator X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Jan 2020 17:02:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579107731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=CyzKldE/6Cgen2AgCmOMvphkJtHVLcVX5ZnXvfwctTg=; b=W8EOBq8Ndu86Iko8DG6egfFCLcBcAQoIuFiS3mFKkZOANb4e4mQiI5OuJGsx83ved10s2a efIG/M4yUdIxTmKkD5F1EKCnU6NN3QIBFqZy8oj1JFykD7CWL2RFVUKB9CZ7PHVkgegdgl T8+G5/P1jvkozdj8iV4Y1lEVVhk+JX4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-377-6RRn8rlpOkmyZ9hKt9JeGQ-1; Wed, 15 Jan 2020 12:02:07 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A61531005510; Wed, 15 Jan 2020 17:02:06 +0000 (UTC) Received: from localhost (unknown [10.33.36.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 332AC19756; Wed, 15 Jan 2020 17:02:06 +0000 (UTC) Date: Wed, 15 Jan 2020 21:49:00 -0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Fix weakly_incrementable to allow __int128 (PR 93267) Message-ID: <20200115170205.GA548679@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Mimecast-Spam-Score: 0 Content-Type: multipart/mixed; boundary="Kj7319i9nmIyA2yE" Content-Disposition: inline X-IsSubscribed: yes X-SW-Source: 2020-01/txt/msg00088.txt.bz2 --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 1477 The __iota_diff_t alias can be the type __int128, but that does not satisfy the signed_integral and __is_signed_integer_like concepts when __STRICT_ANSI__ is defined (which is true for -std=3Dc++2a). Because weakly_incrementable is defined in terms of signed_integral, it is not satisfied by __int128, which means iota_view's iterator doesn't always satisfy input_or_output_iterator and so iota_view is not always a range. The solution is to define __max_size_type and __max_diff_type using __int128, so that __is_signed_integer_like allows __int128, and then make weakly_incrementable use __is_signed_integer_like instead of signed_integral. PR libstdc++/93267 * include/bits/iterator_concepts.h (__max_diff_type, __max_size_type): Move here from and define using __int128 when available. (__is_integer_like, __is_signed_integer_like): Move here from . (weakly_incrementable): Use __is_signed_integer_like. * include/bits/range_access.h (__max_diff_type, __max_size_type) (__is_integer_like, __is_signed_integer_like): Move to . (__make_unsigned_like_t): Move here from . * include/std/ranges (__make_unsigned_like_t): Move to . (iota_view): Replace using-directive with using-declarations. * testsuite/std/ranges/iota/93267.cc: New test. * testsuite/std/ranges/iota_view.cc: Move to new 'iota' sub-directory. Tested powerpc64le-linux, committed to trunk. --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" Content-Transfer-Encoding: quoted-printable Content-length: 7834 commit 2a0f6c61b4db19535c632be68bddad74b6adb6cf Author: Jonathan Wakely Date: Wed Jan 15 14:09:35 2020 +0000 libstdc++: Fix weakly_incrementable to allow __int128 (PR 93267) =20=20=20=20 The __iota_diff_t alias can be the type __int128, but that does not satisfy the signed_integral and __is_signed_integer_like concepts when __STRICT_ANSI__ is defined (which is true for -std=3Dc++2a). =20=20=20=20 Because weakly_incrementable is defined in terms of signed_integral, it is not satisfied by __int128, which means iota_view's iterator doesn't always satisfy input_or_output_iterator and so iota_view is not always a range. =20=20=20=20 The solution is to define __max_size_type and __max_diff_type using __int128, so that __is_signed_integer_like allows __int128, and then make weakly_incrementable use __is_signed_integer_like instead of signed_integral. =20=20=20=20 PR libstdc++/93267 * include/bits/iterator_concepts.h (__max_diff_type, __max_size= _type): Move here from and define using __int128 = when available. (__is_integer_like, __is_signed_integer_like): Move here from . (weakly_incrementable): Use __is_signed_integer_like. * include/bits/range_access.h (__max_diff_type, __max_size_type) (__is_integer_like, __is_signed_integer_like): Move to . (__make_unsigned_like_t): Move here from . * include/std/ranges (__make_unsigned_like_t): Move to . (iota_view): Replace using-directive with using-declarations. * testsuite/std/ranges/iota/93267.cc: New test. * testsuite/std/ranges/iota_view.cc: Move to new 'iota' sub-dir= ectory. diff --git a/libstdc++-v3/include/bits/iterator_concepts.h b/libstdc++-v3/i= nclude/bits/iterator_concepts.h index 4ba32a0859e..bf581597229 100644 --- a/libstdc++-v3/include/bits/iterator_concepts.h +++ b/libstdc++-v3/include/bits/iterator_concepts.h @@ -492,6 +492,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION =3D std::forward<_Tp>(__t); }; =20 + namespace ranges::__detail + { +#if __SIZEOF_INT128__ + using __max_diff_type =3D __int128; + using __max_size_type =3D unsigned __int128; +#else + using __max_diff_type =3D long long; + using __max_size_type =3D unsigned long long; +#endif + + template + concept __is_integer_like =3D integral<_Tp> + || same_as<_Tp, __max_diff_type> || same_as<_Tp, __max_size_type>; + + template + concept __is_signed_integer_like =3D signed_integral<_Tp> + || same_as<_Tp, __max_diff_type>; + + } // namespace ranges::__detail + + namespace __detail { using ranges::__detail::__is_signed_integer_like; } + /// Requirements on types that can be incremented with ++. template concept weakly_incrementable =3D default_initializable<_Iter> @@ -499,7 +521,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION && requires(_Iter __i) { typename iter_difference_t<_Iter>; - requires signed_integral>; + requires __detail::__is_signed_integer_like>; { ++__i } -> same_as<_Iter&>; __i++; }; diff --git a/libstdc++-v3/include/bits/range_access.h b/libstdc++-v3/includ= e/bits/range_access.h index 721c755f48c..8b546a58840 100644 --- a/libstdc++-v3/include/bits/range_access.h +++ b/libstdc++-v3/include/bits/range_access.h @@ -347,22 +347,15 @@ namespace ranges =20 namespace __detail { - using __max_diff_type =3D long long; - using __max_size_type =3D unsigned long long; - - template - concept __is_integer_like =3D integral<_Tp> - || same_as<_Tp, __max_diff_type> || same_as<_Tp, __max_size_type>; - - template - concept __is_signed_integer_like =3D signed_integral<_Tp> - || same_as<_Tp, __max_diff_type>; - template constexpr make_unsigned_t<_Tp> __to_unsigned_like(_Tp __t) noexcept { return __t; } =20 + template> + using __make_unsigned_like_t + =3D conditional_t<_MaxDiff, __max_size_type, make_unsigned_t<_Tp>>; + // Part of the constraints of ranges::safe_range template concept __maybe_safe_range diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ran= ges index 888414a8fd6..ea558c76c9d 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -244,10 +244,6 @@ namespace ranges =3D !range<_Tp> && __pair_like<_Tp> && sentinel_for, tuple_element_t<0, _Tp>>; =20 - template> - using __make_unsigned_like_t - =3D conditional_t<_MaxDiff, __max_size_type, make_unsigned_t<_Tp>>; - } // namespace __detail =20 enum class subrange_kind : bool { unsized, sized }; @@ -717,7 +713,8 @@ namespace ranges constexpr _Iterator& operator+=3D(difference_type __n) requires __detail::__advanceable<_Winc> { - using namespace __detail; + using __detail::__is_integer_like; + using __detail::__is_signed_integer_like; if constexpr (__is_integer_like<_Winc> && !__is_signed_integer_like<_Winc>) { @@ -734,7 +731,8 @@ namespace ranges constexpr _Iterator& operator-=3D(difference_type __n) requires __detail::__advanceable<_Winc> { - using namespace __detail; + using __detail::__is_integer_like; + using __detail::__is_signed_integer_like; if constexpr (__is_integer_like<_Winc> && !__is_signed_integer_like<_Winc>) { @@ -804,7 +802,8 @@ namespace ranges operator-(const _Iterator& __x, const _Iterator& __y) requires __detail::__advanceable<_Winc> { - using namespace __detail; + using __detail::__is_integer_like; + using __detail::__is_signed_integer_like; using _Dt =3D difference_type; if constexpr (__is_integer_like<_Winc>) { @@ -892,7 +891,8 @@ namespace ranges || (integral<_Winc> && integral<_Bound>) || sized_sentinel_for<_Bound, _Winc> { - using namespace __detail; + using __detail::__is_integer_like; + using __detail::__to_unsigned_like; if constexpr (__is_integer_like<_Winc> && __is_integer_like<_Bound>) return (_M_value < 0) ? ((_M_bound < 0) diff --git a/libstdc++-v3/testsuite/std/ranges/iota/93267.cc b/libstdc++-v3= /testsuite/std/ranges/iota/93267.cc new file mode 100644 index 00000000000..39b3c771b54 --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/iota/93267.cc @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=3Dc++2a" } +// { dg-do compile { target c++2a } } + +#include + +void +test01() +{ + // PR libstdc++/93267 + std::ranges::iota_view i(0, 3); + static_assert( std::weakly_incrementable ); + (void) std::ranges::begin(i); +} --Kj7319i9nmIyA2yE--