diff mbox series

[2/1] libstdc++: Add missing friend declaration to join_view::_Sentinel

Message ID 20200305162409.2723743-1-ppalka@redhat.com
State New
Headers show
Series None | expand

Commit Message

Patrick Palka March 5, 2020, 4:24 p.m. UTC
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/include/std/ranges               |  2 ++
 .../testsuite/std/ranges/adaptors/join.cc     | 23 +++++++++++++++++++
 2 files changed, 25 insertions(+)

Comments

Jonathan Wakely March 5, 2020, 4:56 p.m. UTC | #1
On 05/03/20 11:24 -0500, Patrick Palka wrote:
>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.

OK.
Patrick Palka March 5, 2020, 6:28 p.m. UTC | #2
On Thu, 5 Mar 2020, Jonathan Wakely wrote:

> On 05/03/20 11:24 -0500, Patrick Palka wrote:
> > 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.
> 
> OK.

Thanks for the review.  Unfortunately the added test fails to compile
without first a fix for PR 93978 (or alternatively, we can add -O0 to
dg-options in join.cc).
diff mbox series

Patch

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 57edc895e3d..16195812b70 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -2593,6 +2593,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();
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
index d3e652da009..142c9feddcd 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
@@ -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();
 }