From patchwork Tue May 18 19:52:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1480459 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=r/etBbWE; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fl69p5VdTz9sVt for ; Wed, 19 May 2021 05:53:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C42D7395B458; Tue, 18 May 2021 19:52:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C42D7395B458 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621367575; bh=le8VildTvVA7mg3aDYOElYNUrsn73VALtZkI68zn0UI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=r/etBbWETQNkPUEdSEqSUjGWljgCqF31vSdN0RNNKqpvaR2cz7NnQO3qW2t5BmOuq Dwyj/sOB7JZnbp5VzTlnJuV0zFI8SCiTH/ot+iKxVEFteBcgmPhvC0zp9oxw6oKP7I PngONlxw704Nz5adVdekhaG8HFonMzkZEoZLeXeg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 5A7CE3959E72 for ; Tue, 18 May 2021 19:52:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5A7CE3959E72 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-325-Tsa5dRgKMkeILSUfQUTaUg-1; Tue, 18 May 2021 15:52:51 -0400 X-MC-Unique: Tsa5dRgKMkeILSUfQUTaUg-1 Received: by mail-qv1-f71.google.com with SMTP id l19-20020a0ce5130000b02901b6795e3304so8277097qvm.2 for ; Tue, 18 May 2021 12:52:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=le8VildTvVA7mg3aDYOElYNUrsn73VALtZkI68zn0UI=; b=e8Qun0DIHEfNtI9mwQgrfx1BUBSu725bqQaCyL/7dbEJf0AHhGvupijUiB+gn1f9Th xHwabZI1AmmsA3EtwWcR1YTQQKW8EGZg50vKKGgG38QiXjk1ar3NTfG0Y42tgJySwkpM 3xYZlXg7lhmKzA+u4EsFyKnFEVtdLSvYc4OclSoUaaXEpBm4gq6e2ctPwJwjKmEPfC+d p/cJoNBO3LQWpMMpAmFlfmMsh5GKBfuT9apWPXQVpR9q0JgEUaGPNSO1Yt/aNSbHu/94 i1AQJxvdmNkAz88vutH7zrsi+CUyCItjc+NdGHFC9MmAXmWjowiZ4jyJzN8zUtLtshDC 7ifQ== X-Gm-Message-State: AOAM533eyLFVZJjpdU0C8C2vGTupQLU872D61I02VcUVVXFBxKcHJREB rqD69/UZ5BMQ3I48gbOd9JT0FdihoYAv5yC3PsKVv0MXD9a29LFGEMvNlrByPP0Z1zLwSrkt4nf UZhI02zDmWVR5tgjQQDA0a8Zxw+1b6RqQVHM+cYGVT4a6DhGfpzFLotf7bpT1jeMoMg0= X-Received: by 2002:ac8:5fd5:: with SMTP id k21mr6742776qta.231.1621367570077; Tue, 18 May 2021 12:52:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6dAWwwXtpcgAMEC/Veq0UbNuva78Ggj0rw7q1+ppPjQV5d3EAp1ZBY2g4kp3Eel3hXg4D6A== X-Received: by 2002:ac8:5fd5:: with SMTP id k21mr6742743qta.231.1621367569689; Tue, 18 May 2021 12:52:49 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id v10sm13461619qtf.39.2021.05.18.12.52.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 12:52:49 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Implement missing P0896 changes to reverse_view [PR100639] Date: Tue, 18 May 2021 15:52:47 -0400 Message-Id: <20210518195247.1078212-1-ppalka@redhat.com> X-Mailer: git-send-email 2.32.0.rc0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-15.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, URI_HEX autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: libstdc++@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This implements the P0896 changes to reverse_view's member types value_type, difference_type and reference in C++20 mode, which fixes problems taking the reverse_iterator of an iterator with a non-integral difference_type (such as iota_view). Tested on x86_64-pc-linux-gnu, does this look OK for trunk and perhaps 10/11? libstdc++-v3/ChangeLog: PR libstdc++/100639 * include/bits/stl_iterator.h (reverse_view::difference_type): In C++20 mode, define in terms of iter_difference_t as per P0896. (reverse_view::reference): Likewise, but with iter_reference_t. (reverse_view::value_type): Likewise, but with iter_value_t. * testsuite/std/ranges/adaptors/reverse.cc (test08): New test. * testsuite/24_iterators/reverse_iterator/100639.cc: New test. --- libstdc++-v3/include/bits/stl_iterator.h | 9 +++-- .../24_iterators/reverse_iterator/100639.cc | 37 +++++++++++++++++++ .../testsuite/std/ranges/adaptors/reverse.cc | 12 ++++++ 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 libstdc++-v3/testsuite/24_iterators/reverse_iterator/100639.cc diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 2409cd71f86..8768624b7d1 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -149,11 +149,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION public: typedef _Iterator iterator_type; - typedef typename __traits_type::difference_type difference_type; typedef typename __traits_type::pointer pointer; +#if __cplusplus <= 201703L + typedef typename __traits_type::difference_type difference_type; typedef typename __traits_type::reference reference; - -#if __cplusplus > 201703L && __cpp_lib_concepts +#else using iterator_concept = conditional_t, random_access_iterator_tag, @@ -161,6 +161,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using iterator_category = __detail::__clamp_iter_cat; + using value_type = iter_value_t<_Iterator>; + using difference_type = iter_difference_t<_Iterator>; + using reference = iter_reference_t<_Iterator>; #endif /** diff --git a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/100639.cc b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/100639.cc new file mode 100644 index 00000000000..358d91dfef1 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/100639.cc @@ -0,0 +1,37 @@ +// Copyright (C) 2021 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=c++2a" } +// { dg-do compile { target c++2a } } + +// PR libstdc++/100639 + +#include +#include + +void +test01() +{ + using iter = std::ranges::iterator_t>; + using riter = std::reverse_iterator; + static_assert(std::same_as, + std::iter_reference_t>); + static_assert(std::same_as, + std::iter_value_t>); + static_assert(std::same_as, + std::iter_difference_t>); +} diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/reverse.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/reverse.cc index 47e34eb6581..7f1bde1d5d5 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/reverse.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/reverse.cc @@ -161,6 +161,17 @@ test07() static_assert(!requires { 0 | reverse; }); } +void +test08() +{ + // PR libstdc++/100639 + for (auto val + : views::iota(1701ll, 3000ll) + | views::reverse + | views::take(5)) + ; +} + int main() { @@ -171,4 +182,5 @@ main() test05(); test06(); test07(); + test08(); }