From patchwork Fri Jul 22 15:52:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 134 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f503:0:0:0:0:0 with SMTP id q3csp307103wro; Fri, 22 Jul 2022 08:53:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tGhlSXm9FcNF+ZQJmFhrIsVUy1I29tZrSUuR3hn6EKt/EwullS22g2NfXt186mIKy8Hmwp X-Received: by 2002:a50:ee8d:0:b0:43b:b678:114c with SMTP id f13-20020a50ee8d000000b0043bb678114cmr539265edr.12.1658505195094; Fri, 22 Jul 2022 08:53:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658505195; cv=none; d=google.com; s=arc-20160816; b=b5rm8RqpGQg3D2aUvxeqxVoNDkvndixS5dvxwGMTt1Vy/wbHUJBUDyGzygfwDdrlCp 00E9/qU1TrdtsXAywITKY1HQ0WnQW4pSHMN38HhLKy8GDgfsnl04HLamLA7NCUaFz9ap LKL/QBDfbZU3Z9m4iz4+8oFPHp2aJjcwTka9Y4IvBT3Gbqi3p2/BEb1/pqOErGm9qph6 1qzzrisGU0CHNSgNdIPJ4s+OUo5Ij+s/ziEChFzXrdwCGaKHOe1lfzGbSshdhFWr6PVb SQ3UxSmg1oVgPB9yGWdyzV3e3Ka2Wu+0F0KDCaKUg1bOeSDddR+xYwNKyjqjH/KdRwaL FVuA== 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:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=DtuNlNKCcYEdyLgAOQJJWH3DGRDu4qbzlPOSiEDcSZo=; b=TddiNi5OinWI/2eA00x++NwqyitVV6BZMdCsvfTx05kDGoiVQgQveNUYK+ku/7tkvO JBt+ZjcYjk/bCwL11IJS7TrH2WwfY8iurWID5+F2yKNwL1ug1UFOjtnXUYXxogB/UuYu gEpoSQDR1Pn4eQIPOhqPUdDEjwbS/QzItvgzn3vQ2iGoEeUhsjgj/gPtwCCpOi/OxI6U UHA5FqMgGAlo9DeFpC6KzgxuQY/z7zQPmTWIGnSTdHn89afTj01VYjSSA9/z0LChfaJr dYMDMdcU561M7VYF1nMuEfl8/tB7j6dtBaocjDFeOWrASn8wVbs/pbhEyvFvVEzBKY/h nr7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gJPCJlIV; 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 hq34-20020a1709073f2200b0072b5adee783si786385ejc.523.2022.07.22.08.53.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 08:53:15 -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=gJPCJlIV; 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 C42193834E5E for ; Fri, 22 Jul 2022 15:52:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C42193834E5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658505176; bh=DtuNlNKCcYEdyLgAOQJJWH3DGRDu4qbzlPOSiEDcSZo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=gJPCJlIV2vMl2wH3X35viT6uzSGi6erHpqv629ItXPxp/HkHjxr1w+CHFJGtVMkf2 ZmMnmaC9sJDxuoCoPW2TMfLp6r6wPL4aTCzKJmZHz6HCHxh+JzWgCvj0RfOAc7XEMt F7UAX2g50qfIHG9P8cyQ3JqJPskxQQOV+JYVrMV0= 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 6AE7438356AC for ; Fri, 22 Jul 2022 15:52:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6AE7438356AC Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-528-TcMSRed8MpCu8m5ojpOpHQ-1; Fri, 22 Jul 2022 11:52:05 -0400 X-MC-Unique: TcMSRed8MpCu8m5ojpOpHQ-1 Received: by mail-qt1-f197.google.com with SMTP id h21-20020ac87775000000b0031f1f223ccaso1718292qtu.22 for ; Fri, 22 Jul 2022 08:52:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DtuNlNKCcYEdyLgAOQJJWH3DGRDu4qbzlPOSiEDcSZo=; b=ls86xXQTRr+h30HlJ5HBVqq96arFnFht4jo3Lg30IONkngTvguESYS3bySPzxtLIP4 DkdZted5qIRgeWyr640MSBD6Z/zAUYNRZeUHC+pUvurGrqlA6bRnF1jzY/sdzH5FASX2 4WJAmG593Yek80QoBue8AF1ddQM4HumuUYmmvY7Pi8UpwluvyTekeVAPtG0o1sD5KOOo ybgKAtejbXgELX2pykmVNk81dS/2X4PRCfrxv9H+mblUzcehAdELCRpOKE5LL6NhQ2RZ dEGYRhCnrfDSWlZirwH8cvjmZFCAyK19JhzyjRaEFlXXfJa9BAXxINWy4sdBvpvDKwjJ kPmg== X-Gm-Message-State: AJIora/T/ygVFydMLr5Kow5iOp0fv+a3/JY/8h+s+bb9hI063hfSW6JE d+znZm2IXNeEXs/8fNuwuVhZQlkFR45ZjCYhnXuYDCgrciTanv4KEbF5VCgNapsnIMn5IkOLCF4 Lszn8LpkqFxzJY6at9DVoUMoYZBKCdRvBZNqAVfz9OQQzGdZmhSrttBoImBF28pQOY04= X-Received: by 2002:a05:622a:52:b0:31e:ea7c:1add with SMTP id y18-20020a05622a005200b0031eea7c1addmr622218qtw.193.1658505124553; Fri, 22 Jul 2022 08:52:04 -0700 (PDT) X-Received: by 2002:a05:622a:52:b0:31e:ea7c:1add with SMTP id y18-20020a05622a005200b0031eea7c1addmr622197qtw.193.1658505124208; Fri, 22 Jul 2022 08:52:04 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id d4-20020ac851c4000000b0031ed5685862sm3007898qtn.77.2022.07.22.08.52.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 08:52:03 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Fix backward compatibility of P2325R3 backport [PR106320] Date: Fri, 22 Jul 2022 11:52:00 -0400 Message-Id: <20220722155200.1533671-1-ppalka@redhat.com> X-Mailer: git-send-email 2.37.1.208.ge72d93e88c MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.6 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_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable 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: "Li, Pan2 via Gcc-patches" 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?1739068743829118436?= X-GMAIL-MSGID: =?utf-8?q?1739068743829118436?= The 11 and 10 partial backports of P2325R3, r11-9555-g92d612cccc1eec and r10-10808-g22b86cdc4d7fdd, unnecessarily preserved some changes from the paper that made certain views no longer default constructible, changes which aren't required to reap the overall benefits of the paper and which conflicted with the goal to maximize backwards compatibility with pre-P2325R3 code. This patch reverts the problematic changes, specifically it relaxes the constraints on various views' default constructors so that they reflect only the requirements that were already implicitly imposed by the NSDMIs of the view. Thus for example this patch retains the default_initializable<_Vp> constraint on transform_view's default constructor since its '_Vp _M_base = _Vp()' NSDMI already reflects this constraint, and it removes the default_initializable<_Fp> constraint since the corresponding member '__detail::__box<_Fp> _M_fun' doesn't require default initializability (specializations of __box are always default constructible). After reverting these changes, all static_asserts from p2325.cc that verify lack of default constructibility now fail as expected, matching the pre-P2325R3 behavior. Tested on x86_64-pc-linux-gnu, does this look OK for the 11 and 10 branches? PR libstdc++/106320 libstdc++-v3/ChangeLog: * include/std/ranges (single_view): Remove * testsuite/std/ranges/adaptors/join.cc (test13): New test. * testsuite/std/ranges/p2325.cc: Fix S to be only non default constructible and not also non copy constructible. XFAIL the tests that verify a non default constructible functor makes a view non default constructible (lines 94, 97 and 98). XFAIL the test that effectively verifies a non default constructible element type makes single_view non default constructible (line 114). --- libstdc++-v3/include/std/ranges | 18 +++++------------- .../testsuite/std/ranges/adaptors/join.cc | 15 +++++++++++++++ libstdc++-v3/testsuite/std/ranges/p2325.cc | 12 ++++++++---- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index bbdfb7dbe5c..0a67c45f1b8 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -200,7 +200,7 @@ namespace ranges class single_view : public view_interface> { public: - single_view() requires default_initializable<_Tp> = default; + single_view() = default; constexpr explicit single_view(const _Tp& __t) @@ -1463,9 +1463,7 @@ namespace views::__adaptor _Vp _M_base = _Vp(); public: - filter_view() requires (default_initializable<_Vp> - && default_initializable<_Pred>) - = default; + filter_view() requires default_initializable<_Vp> = default; constexpr filter_view(_Vp __base, _Pred __pred) @@ -1829,9 +1827,7 @@ namespace views::__adaptor _Vp _M_base = _Vp(); public: - transform_view() requires (default_initializable<_Vp> - && default_initializable<_Fp>) - = default; + transform_view() requires default_initializable<_Vp> = default; constexpr transform_view(_Vp __base, _Fp __fun) @@ -2150,9 +2146,7 @@ namespace views::__adaptor _Vp _M_base = _Vp(); public: - take_while_view() requires (default_initializable<_Vp> - && default_initializable<_Pred>) - = default; + take_while_view() requires default_initializable<_Vp> = default; constexpr take_while_view(_Vp base, _Pred __pred) @@ -2356,9 +2350,7 @@ namespace views::__adaptor _Vp _M_base = _Vp(); public: - drop_while_view() requires (default_initializable<_Vp> - && default_initializable<_Pred>) - = default; + drop_while_view() requires default_initializable<_Vp> = default; constexpr drop_while_view(_Vp __base, _Pred __pred) diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc index d774e8d9385..14e254bc734 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc @@ -193,6 +193,20 @@ test11() ; } +void +test13() +{ + // PR libstdc++/106320 + auto l = std::views::transform([](auto x) { + return x | std::views::transform([x=0](auto y) { + return y; + }); + }); + static_assert(!std::default_initializable); + std::vector> v{{5, 6, 7}}; + v | l | std::views::join; +} + int main() { @@ -207,4 +221,5 @@ main() test09(); test10(); test11(); + test13(); } diff --git a/libstdc++-v3/testsuite/std/ranges/p2325.cc b/libstdc++-v3/testsuite/std/ranges/p2325.cc index 205b3458928..99f1b0f08f1 100644 --- a/libstdc++-v3/testsuite/std/ranges/p2325.cc +++ b/libstdc++-v3/testsuite/std/ranges/p2325.cc @@ -5,8 +5,8 @@ // Parts of P2325R3 are deliberately omitted in libstdc++ 11, in particular the // removal of default ctors for back_/front_insert_iterator, ostream_iterator, // ref_view and basic_istream_view/::iterator, so as to maximize backward -// compatibility with pre-P2325R3 code. So most static_asserts in this test fail, -// see the xfails at the end of this file. +// compatibility with pre-P2325R3 code. Namely all static_asserts that verify +// lack of default constructibility fail; see the xfails at the end of this file. #include #include @@ -93,7 +93,7 @@ test06() static_assert(default_initializable); static_assert(!default_initializable); - struct S { S() = delete; }; + struct S { S() = delete; S(const S&) = default; S(S&&) = default; }; static_assert(!default_initializable()) | adaptor(f1))>); static_assert(!default_initializable()) | adaptor(f2))>); } @@ -109,7 +109,7 @@ void test07() { // Verify join_view is conditionally default constructible. - struct S { S() = delete; }; + struct S { S() = delete; S(const S&) = default; S(S&&) = default; }; using type1 = ranges::join_view>>; static_assert(!default_initializable); using type2 = ranges::join_view>>; @@ -173,6 +173,10 @@ test11() // { dg-bogus "static assertion failed" "" { xfail *-*-* } 76 } // { dg-bogus "static assertion failed" "" { xfail *-*-* } 77 } // { dg-bogus "static assertion failed" "" { xfail *-*-* } 84 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 94 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 97 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 98 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 114 } // { dg-bogus "static assertion failed" "" { xfail *-*-* } 124 } // { dg-bogus "static assertion failed" "" { xfail *-*-* } 126 } // { dg-bogus "static assertion failed" "" { xfail *-*-* } 128 }