libstdc++: Add missing friend declaration to join_view::_Sentinel
authorPatrick Palka <ppalka@redhat.com>
Thu, 5 Mar 2020 16:19:17 +0000 (11:19 -0500)
committerPatrick Palka <ppalka@redhat.com>
Fri, 6 Mar 2020 14:23:10 +0000 (09:23 -0500)
The converting constructor of join_view::_Sentinel<true> needs to be able to
access the private members of join_view::_Sentinel<false>.

libstdc++-v3/ChangeLog:

* include/std/ranges (join_view::_Sentinel<_Const>): Befriend
join_view::_Sentinel<!_Const>.
* testsuite/std/ranges/adaptors/join.cc: Augment test.

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/std/ranges/adaptors/join.cc

index b2e995b..b3e8b9a 100644 (file)
@@ -1,5 +1,9 @@
 2020-03-06  Patrick Palka  <ppalka@redhat.com>
 
+       * include/std/ranges (join_view::_Sentinel<_Const>): Befriend
+       join_view::_Sentinel<!_Const>.
+       * testsuite/std/ranges/adaptors/join.cc: Augment test.
+
        PR libstdc++/93978
        * include/bits/range_access.h (__cust_access::_Empty::operator()):
        Declare return type to be bool instead of auto.
index c71cf91..eb54b11 100644 (file)
@@ -2592,6 +2592,8 @@ namespace views
          friend constexpr bool
          operator==(const _Iterator<_Const>& __x, const _Sentinel& __y)
          { return __y.__equal(__x); }
+
+         friend _Sentinel<!_Const>;
        };
 
       _Vp _M_base = _Vp();
index d3e652d..142c9fe 100644 (file)
@@ -101,6 +101,28 @@ test05()
   VERIFY( i == v.end() );
 }
 
+void
+test06()
+{
+  std::vector<std::string> x = {""};
+  auto i = std::counted_iterator(x.begin(), 1);
+  auto r = ranges::subrange{i, std::default_sentinel};
+  auto v = r | views::transform(std::identity{}) | views::join;
+
+  // Verify that _Iterator<false> is implicitly convertible to _Iterator<true>.
+  static_assert(!std::same_as<decltype(ranges::begin(v)),
+                             decltype(ranges::cbegin(v))>);
+  auto a = ranges::cbegin(v);
+  a = ranges::begin(v);
+
+  // Verify that _Sentinel<false> is implicitly convertible to _Sentinel<true>.
+  static_assert(!ranges::common_range<decltype(v)>);
+  static_assert(!std::same_as<decltype(ranges::end(v)),
+                             decltype(ranges::cend(v))>);
+  auto b = ranges::cend(v);
+  b = ranges::end(v);
+}
+
 int
 main()
 {
@@ -109,4 +131,5 @@ main()
   test03();
   test04();
   test05();
+  test06();
 }