public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10908] libstdc++: Fix backward compatibility of P2325R3 backport [PR106320]
@ 2022-07-22 17:06 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2022-07-22 17:06 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:2cad5c5c2de819b7a5177aa87e5e2fd088357b01

commit r10-10908-g2cad5c5c2de819b7a5177aa87e5e2fd088357b01
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Jul 22 12:52:03 2022 -0400

    libstdc++: Fix backward compatibility of P2325R3 backport [PR106320]
    
    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 view specializations no longer default
    constructible, changes which aren't required to reap the overall benefits
    of the paper and which are backward incompatible with pre-P2325R3 code in
    practice.
    
    This patch reverts the problematic changes, specifically it relaxes the
    constraints on various views' default constructors added by the paper
    so that we keep only the constraints 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 requires this
    constraint, and it removes the default_initializable<_Fp> constraint
    since the corresponding member '__detail::__box<_Fp> _M_fun' doesn't
    require default constructibility (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.
    
            PR libstdc++/106320
    
    libstdc++-v3/ChangeLog:
    
            * include/std/ranges (single_view): Relax constraints on
            default constructor so as to preserve pre-P2325R3 behavior.
            (filter_view): Likewise.
            (transform_view): Likewise.
            (take_while_view): Likewise.
            (drop_while_view): Likewise.
            * 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).
    
    (cherry picked from commit 36dd51bf87e1c533bf33ad3b16fd3fe06c356746)

Diff:
---
 libstdc++-v3/include/std/ranges                    | 18 +++++-------------
 libstdc++-v3/testsuite/std/ranges/adaptors/join.cc | 16 ++++++++++++++++
 libstdc++-v3/testsuite/std/ranges/p2325.cc         | 12 ++++++++----
 3 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 17018a5616c..faa55ebceb7 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -518,7 +518,7 @@ namespace ranges
     class single_view : public view_interface<single_view<_Tp>>
     {
     public:
-      single_view() requires default_initializable<_Tp> = default;
+      single_view() = default;
 
       constexpr explicit
       single_view(const _Tp& __t)
@@ -1592,9 +1592,7 @@ namespace views
       [[no_unique_address]] __detail::_CachedPosition<_Vp> _M_cached_begin;
 
     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)
@@ -1940,9 +1938,7 @@ namespace views
       __detail::__box<_Fp> _M_fun;
 
     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)
@@ -2220,9 +2216,7 @@ namespace views
       __detail::__box<_Pred> _M_pred;
 
     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)
@@ -2389,9 +2383,7 @@ namespace views
       [[no_unique_address]] __detail::_CachedPosition<_Vp> _M_cached_begin;
 
     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 9c0231b704b..c75fb8142cc 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
@@ -159,6 +159,21 @@ test10()
   VERIFY( ranges::next(v.begin()) == v.end() );
 }
 
+
+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<decltype(l)>);
+  std::vector<std::vector<int>> v{{5, 6, 7}};
+  v | l | std::views::join;
+}
+
 int
 main()
 {
@@ -171,4 +186,5 @@ main()
   test07();
   test08();
   test10();
+  test13();
 }
diff --git a/libstdc++-v3/testsuite/std/ranges/p2325.cc b/libstdc++-v3/testsuite/std/ranges/p2325.cc
index aff3bd6ca28..8dbce6d6db8 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++ 10, 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 asserts that verify lack of
+// default constructibility fail; see the xfails at the end of this file.
 
 #include <ranges>
 #include <iterator>
@@ -93,7 +93,7 @@ test06()
   static_assert(default_initializable<decltype(views::single(0) | adaptor(f1))>);
   static_assert(!default_initializable<decltype(views::single(0) | adaptor(f2))>);
 
-  struct S { S() = delete; };
+  struct S { S() = delete; S(const S&) = default; S(S&&) = default; };
   static_assert(!default_initializable<decltype(views::single(declval<S>()) | adaptor(f1))>);
   static_assert(!default_initializable<decltype(views::single(declval<S>()) | 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<ranges::single_view<ranges::single_view<S>>>;
   static_assert(!default_initializable<type1>);
   using type2 = ranges::join_view<ranges::single_view<ranges::single_view<int>>>;
@@ -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 }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-22 17:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-22 17:06 [gcc r10-10908] libstdc++: Fix backward compatibility of P2325R3 backport [PR106320] Patrick Palka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).