public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r10-9049] libstdc++: Fix ranges::join_view::_Iterator::operator-> [LWG 3500]
Date: Wed, 18 Nov 2020 16:11:55 +0000 (GMT)	[thread overview]
Message-ID: <20201118161155.A7A573854821@sourceware.org> (raw)

https://gcc.gnu.org/g:fd6b319c84fcf2d8881b256d145499e726d94571

commit r10-9049-gfd6b319c84fcf2d8881b256d145499e726d94571
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Nov 18 10:23:57 2020 -0500

    libstdc++: Fix ranges::join_view::_Iterator::operator-> [LWG 3500]
    
    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.
    
    (cherry picked from commit d4a788c7174496aca5fbe3e2b617a5a62e32c209)

Diff:
---
 libstdc++-v3/include/std/ranges                    | 14 ++++++++------
 libstdc++-v3/testsuite/std/ranges/adaptors/join.cc | 12 ++++++++++++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 5625b0ba1a3..e2ad6a313c7 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -2421,9 +2421,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;
 	      }
 
@@ -2504,10 +2504,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&
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
index e21e7054b35..8bbea9a6b25 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
@@ -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();
 }


                 reply	other threads:[~2020-11-18 16:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201118161155.A7A573854821@sourceware.org \
    --to=ppalka@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).