From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 2C5EC38356A7 for ; Fri, 22 Jul 2022 15:52:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2C5EC38356A7 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-646-qGNXJECTMhifeuza5HW7pQ-1; Fri, 22 Jul 2022 11:52:05 -0400 X-MC-Unique: qGNXJECTMhifeuza5HW7pQ-1 Received: by mail-qk1-f197.google.com with SMTP id f20-20020a05620a409400b006b5fc740485so3999604qko.12 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=FOtfvI9WctAX8M0iCaSzQ3LIySw1Z1UtMtiAB6MUNH2pZ/fCtvpWAT1Krqi3eP2N1K Ls++XeoaoIaFRlam2MQaqEt74O3uI91lVKdO5B5ynReC5dNx5/BtTL7IMd22zBUdzcdr eU3X4BHxDykKObI1folLODqDvPKy1+7TmD4E8hb13emQyDB+Cp2Uf8G7FUeRChhkHFxf ws7oafC7m63IIeSKp9CWYQiPydz4NpAFrLlFYnA35ZJHGOfbldlHLeqrciWZDd7isWRN S8uTiI25nX2Nm4O3SRFXb1Ch3dE9Pp2+QG1E0r8wONtaMTkJuolwqE8pdggvF8/QzPt6 RXCw== X-Gm-Message-State: AJIora+giezSC1dk+hpHiJhZyI1d0Aq0kQgHKrUPPwDPhO+aS8xEmJ5e I0dxLYWUj9yRfaJGZ7r79wUGaO1vJnoyXdfEwnPzfLEpNyMuxYTlcBL6APy4VacbnIW3Zp+0iiV WCdrAkW8g3DBeZFg= X-Received: by 2002:a05:622a:52:b0:31e:ea7c:1add with SMTP id y18-20020a05622a005200b0031eea7c1addmr622213qtw.193.1658505124495; Fri, 22 Jul 2022 08:52:04 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uG48AMxEgZQ1uZl0WHIdfQS+JkHNfEhUvh2+by6I/Xz+EMvPQY7bCWhF2yamwpu69+eGK8Kg== 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) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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_NONE, SPF_HELO_NONE, SPF_NONE, TXREP 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: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jul 2022 15:52:13 -0000 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 } -- 2.37.1.208.ge72d93e88c