libstdc++: Fix ranges::join_view::_Iterator::operator-> [LWG 3500]
authorPatrick Palka <ppalka@redhat.com>
Wed, 18 Nov 2020 15:23:57 +0000 (10:23 -0500)
committerPatrick Palka <ppalka@redhat.com>
Wed, 18 Nov 2020 15:23:57 +0000 (10:23 -0500)
This applies the proposed resolution of LWG 3500, which corrects the
return type and constraints of this member function to use the right
iterator type.  Additionally, a nearby local variable is uglified.

libstdc++-v3/ChangeLog:

* include/std/ranges (join_view::_Iterator::_M_satisfy): Uglify
local variable inner.
(join_view::_Iterator::operator->): Use _Inner_iter instead of
_Outer_iter in the function signature as per LWG 3500.
* testsuite/std/ranges/adaptors/join.cc (test08): Test it.

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

index 14d2a11f7fb67b39d8c774bd4945a8db05f6b85e..d38b1998de9ba7f1c96bae25dc5975a560351e52 100644 (file)
@@ -2128,9 +2128,9 @@ namespace views
 
            for (; _M_outer != ranges::end(_M_parent->_M_base); ++_M_outer)
              {
-               auto& inner = __update_inner(*_M_outer);
-               _M_inner = ranges::begin(inner);
-               if (_M_inner != ranges::end(inner))
+               auto& __inner = __update_inner(*_M_outer);
+               _M_inner = ranges::begin(__inner);
+               if (_M_inner != ranges::end(__inner))
                  return;
              }
 
@@ -2211,10 +2211,12 @@ namespace views
          operator*() const
          { return *_M_inner; }
 
-         constexpr _Outer_iter
+         // _GLIBCXX_RESOLVE_LIB_DEFECTS
+         // 3500. join_view::iterator::operator->() is bogus
+         constexpr _Inner_iter
          operator->() const
-           requires __detail::__has_arrow<_Outer_iter>
-             && copyable<_Outer_iter>
+           requires __detail::__has_arrow<_Inner_iter>
+             && copyable<_Inner_iter>
          { return _M_inner; }
 
          constexpr _Iterator&
index e21e7054b3508ed18e808ff4ac16fc06230ade25..8bbea9a6b25f04b830a67a9f76c5e9a0a2745a30 100644 (file)
@@ -138,6 +138,17 @@ test07()
   static_assert( std::same_as<std::ranges::range_value_t<V>, int> );
 }
 
+void
+test08()
+{
+  // LWG 3500. join_view::iterator::operator->() is bogus
+  struct X { int a; };
+  ranges::single_view<ranges::single_view<X>> s{std::in_place, std::in_place, 5};
+  auto v = s | views::join;
+  auto i = v.begin();
+  VERIFY( i->a == 5 );
+}
+
 int
 main()
 {
@@ -148,4 +159,5 @@ main()
   test05();
   test06();
   test07();
+  test08();
 }