From patchwork Mon Sep 12 16:45:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1168 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp1964535wrt; Mon, 12 Sep 2022 09:49:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR6O9HQt6ry7tsMKJd0ZrI47WewtPYgH2Dh6peKzq197kvi4v2Trelav9YPJu4dTYQcZnKW+ X-Received: by 2002:a17:907:75c1:b0:72f:248d:5259 with SMTP id jl1-20020a17090775c100b0072f248d5259mr19789169ejc.227.1663001343497; Mon, 12 Sep 2022 09:49:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663001343; cv=none; d=google.com; s=arc-20160816; b=Hw3ukDVuflpAMbA3Vv1c413AWGHwGBaE040g+RGJUwHA2nsNFW349vYcOEqP0ahYwJ UctINSa55OjBYAAtrNLbu+G8tZvlaMVCPXChri8FQFMBibkR1J9JqKgY7Evvk9MG61ql c1xYLDkv5VVHzHIOgfMGZI/IZdPjZHZtHVx1e2jBNOQUDbLTLAj+OUWZfL2RjGt/oidH EpvyVeFaAFEtlJvTWCgwpX0yOZe1E24oBxfNRIEU9NRKG4rsSsv7W2HcfNWVqrQc4XbK wEYK90L5tFONg5ooDUOt6amgKwVbZzDwf7yFXBvnnyXY49Bfc+sVSUBBWSBxFxLT3E1f 7cfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=x4ZYrG2d13Kk/6s+RjiiA6vGLL0TbNaWFHnV4B78tfo=; b=mFkRkAldaRoBQdtkasgYSs7A9gM8at6F918v9yE97J9f2Pxo/u3eXs/B+JkceOgsEX bDX/yNFz25PROvg423DVyr6u9TXliIxLSRzPbfXrsppqpZM0NxIzVCdLh1jeod5P0WQx 2utYb2xik3B6bzy2bvi49UBhdoQV5oRTsYu6ZxjJ3Bnz8F5/sEp4uR62tWd3rzpndnJu DNynpzDHCIVGUmGeTDxfhAjZH3HcTUo1iEx7QQ2VZOPRUvntV0QGRCPFRh+uqod1x7Q8 +8c5jodQQ7NNQY7QvAGG+R2phyFgH7o5TacQEaq4iblspw48o+MupIIK2fQ24p3rxrEX HMkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GeVx1Ydx; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id l26-20020a50d6da000000b00445d00730b3si7677999edj.416.2022.09.12.09.49.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 09:49:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GeVx1Ydx; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 744AF393BA74 for ; Mon, 12 Sep 2022 16:47:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 744AF393BA74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663001249; bh=x4ZYrG2d13Kk/6s+RjiiA6vGLL0TbNaWFHnV4B78tfo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=GeVx1YdxY8NEjCWN0t99Snvab9XTQ8feTC+IFSyzK14Vh4/fm69zqp8sfkoq2vU8+ Qgy0KcKRIx9k1oyHwT8/hE2II75Pk2fzC5cJ9NhX5u/RLKYu6ctSD9s+09J5D4pAsi SJF/b2zKCtDRdERyxnseF6yZsTRrBzPifd0/mYOQ= 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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 8A01A38A8152 for ; Mon, 12 Sep 2022 16:45:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8A01A38A8152 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-192-widRYh8AOSWUyUuQ_KjxvQ-1; Mon, 12 Sep 2022 12:45:42 -0400 X-MC-Unique: widRYh8AOSWUyUuQ_KjxvQ-1 Received: by mail-qv1-f69.google.com with SMTP id ec8-20020ad44e68000000b004aab01f3eaaso6125772qvb.4 for ; Mon, 12 Sep 2022 09:45:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=x4ZYrG2d13Kk/6s+RjiiA6vGLL0TbNaWFHnV4B78tfo=; b=17ln7Kq1OiivinBHkn2fyj0P1NezbmOHW0mNiQ7RpRXifO/08lIuuZB5NL1lOIEmDT VNUp0DH60SCWgJYXGM0NbtDE4kWVFV05fT+QP5Hk2SqmSvaRnsyWV+0VdZ6lZEofUmF0 Ny9rQ+rbB/qBDAaOqmWkGZMAcEj9E5/ib9SkKGqhirchKLS4InT16y1l0iTGq7SZjggR dkmjMfXO5Ntk03gHkeI1dFGlPWMhjYNqRpkYvWivxgUJwqEobPtb5BiN0e9o53l03iH+ esJIEJaTv9K8MtOOqw5ie34LEkpiPcBU0e/VzuSJYZmITrczacMBdDbH8Is5xbrMZ6H1 0rXg== X-Gm-Message-State: ACgBeo0tzbiuekaSHfddaD5MoFZpTeUNGgo4VccYIim3PNCuxEbJMbYl gZy6HIbCLuPlGXhDFFWvpi40gahpuuMUChXI+c+oT25YUzrWM/mTDoJ7hZtP4tykhPoQC0NugsV +tB42M+FwpGOS5BrgLdWnXZWBzFVHu0FC6gQhElVTXsPwZnef/nXnXuUoSG1BIoR0DBE= X-Received: by 2002:a05:620a:124f:b0:6cd:ef55:544c with SMTP id a15-20020a05620a124f00b006cdef55544cmr9030247qkl.158.1663001141550; Mon, 12 Sep 2022 09:45:41 -0700 (PDT) X-Received: by 2002:a05:620a:124f:b0:6cd:ef55:544c with SMTP id a15-20020a05620a124f00b006cdef55544cmr9030231qkl.158.1663001141230; Mon, 12 Sep 2022 09:45:41 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id 17-20020ac85651000000b0035ba48c032asm6667350qtt.25.2022.09.12.09.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 09:45:40 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/4] libstdc++: Implement LWG 3569 changes to join_view::_Iterator Date: Mon, 12 Sep 2022 12:45:29 -0400 Message-Id: <20220912164531.1742034-2-ppalka@redhat.com> X-Mailer: git-send-email 2.37.3.542.gdd3f6c4cae In-Reply-To: <20220912164531.1742034-1-ppalka@redhat.com> References: <20220912164531.1742034-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743783296811191677?= X-GMAIL-MSGID: =?utf-8?q?1743783296811191677?= Tested on x86_64-pc-linux-gnu, does this look OK for trunk only? libstdc++-v3/ChangeLog: * include/std/ranges (join_view::_Iterator::_M_satisfy): Adjust resetting _M_inner as per LWG 3569. (join_view::_Iterator::_M_inner): Wrap in std::optional as per LWG 3569. (join_view::_Iterator::_Iterator): Relax constraints as per LWG 3569. (join_view::_Iterator::operator*): Adjust as per LWG 3569. (join_view::_Iterator::operator->): Likewise. (join_view::_Iterator::operator++): Likewise. (join_view::_Iterator::operator--): Likewise. (join_view::_Iterator::iter_move): Likewise. (join_view::_Iterator::iter_swap): Likewise. * testsuite/std/ranges/adaptor/join.cc (test14): New test. --- libstdc++-v3/include/std/ranges | 28 +++++++++---------- .../testsuite/std/ranges/adaptors/join.cc | 17 +++++++++++ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 20eb4e82ac8..6297ce7cee3 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -2746,7 +2746,7 @@ namespace views::__adaptor } if constexpr (_S_ref_is_glvalue) - _M_inner = _Inner_iter(); + _M_inner.reset(); } static constexpr auto @@ -2769,7 +2769,7 @@ namespace views::__adaptor using _Inner_iter = join_view::_Inner_iter<_Const>; _Outer_iter _M_outer = _Outer_iter(); - _Inner_iter _M_inner = _Inner_iter(); + optional<_Inner_iter> _M_inner; _Parent* _M_parent = nullptr; public: @@ -2780,9 +2780,7 @@ namespace views::__adaptor = common_type_t, range_difference_t>>; - _Iterator() requires (default_initializable<_Outer_iter> - && default_initializable<_Inner_iter>) - = default; + _Iterator() requires default_initializable<_Outer_iter> = default; constexpr _Iterator(_Parent* __parent, _Outer_iter __outer) @@ -2801,7 +2799,7 @@ namespace views::__adaptor constexpr decltype(auto) operator*() const - { return *_M_inner; } + { return **_M_inner; } // _GLIBCXX_RESOLVE_LIB_DEFECTS // 3500. join_view::iterator::operator->() is bogus @@ -2809,7 +2807,7 @@ namespace views::__adaptor operator->() const requires __detail::__has_arrow<_Inner_iter> && copyable<_Inner_iter> - { return _M_inner; } + { return *_M_inner; } constexpr _Iterator& operator++() @@ -2820,7 +2818,7 @@ namespace views::__adaptor else return *_M_parent->_M_inner; }(); - if (++_M_inner == ranges::end(__inner_range)) + if (++*_M_inner == ranges::end(__inner_range)) { ++_M_outer; _M_satisfy(); @@ -2850,9 +2848,9 @@ namespace views::__adaptor { if (_M_outer == ranges::end(_M_parent->_M_base)) _M_inner = ranges::end(*--_M_outer); - while (_M_inner == ranges::begin(*_M_outer)) - _M_inner = ranges::end(*--_M_outer); - --_M_inner; + while (*_M_inner == ranges::begin(*_M_outer)) + *_M_inner = ranges::end(*--_M_outer); + --*_M_inner; return *this; } @@ -2879,14 +2877,14 @@ namespace views::__adaptor friend constexpr decltype(auto) iter_move(const _Iterator& __i) - noexcept(noexcept(ranges::iter_move(__i._M_inner))) - { return ranges::iter_move(__i._M_inner); } + noexcept(noexcept(ranges::iter_move(*__i._M_inner))) + { return ranges::iter_move(*__i._M_inner); } friend constexpr void iter_swap(const _Iterator& __x, const _Iterator& __y) - noexcept(noexcept(ranges::iter_swap(__x._M_inner, __y._M_inner))) + noexcept(noexcept(ranges::iter_swap(*__x._M_inner, *__y._M_inner))) requires indirectly_swappable<_Inner_iter> - { return ranges::iter_swap(__x._M_inner, __y._M_inner); } + { return ranges::iter_swap(*__x._M_inner, *__y._M_inner); } friend _Iterator; template friend struct _Sentinel; diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc index 530ab6663b5..afc11d4bd7a 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -217,6 +218,21 @@ test13() std::vector> v{{5, 6, 7}}; v | l | std::views::join; } + +void +test14() +{ + // LWG 3569: join_view fails to support ranges of ranges with + // non-default_initializable iterators + auto ss = std::istringstream{"1 2 3"}; + auto v = views::single(views::istream(ss)); + using inner = ranges::range_reference_t; + static_assert(ranges::input_range + && !ranges::forward_range + && !std::default_initializable>); + VERIFY( ranges::equal(v | views::join, (int[]){1, 2, 3}) ); +} + int main() { @@ -233,4 +249,5 @@ main() test11(); test12(); test13(); + test14(); }