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-9789] libstdc++: Fix up lambda in join_view::_Iterator::operator++ [PR100290]
Date: Mon,  3 May 2021 20:10:17 +0000 (GMT)	[thread overview]
Message-ID: <20210503201017.B6FB73943541@sourceware.org> (raw)

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

commit r10-9789-gb81834eaf85d5c4e0df8e4fc2307cbdd083dea6c
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Apr 27 14:07:46 2021 -0400

    libstdc++: Fix up lambda in join_view::_Iterator::operator++ [PR100290]
    
    Currently, the return type of this lambda is decltype(auto), so the
    lambda ends up returning a copy of _M_parent->_M_inner rather than a
    reference to it when _S_ref_glvalue is false.  This means _M_inner and
    ranges::end(__inner_range) are respectively an iterator and sentinel for
    different ranges, so comparing them is undefined.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/100290
            * include/std/ranges (join_view::_Iterator::operator++): Correct
            the return type of the lambda to avoid returning a copy of
            _M_parent->_M_inner.
            * testsuite/std/ranges/adaptors/join.cc (test10): New test.
    
    (cherry picked from commit 85ef4b8d4eb3313a48b79c7e752891f9646bb246)

Diff:
---
 libstdc++-v3/include/std/ranges                    |  2 +-
 libstdc++-v3/testsuite/std/ranges/adaptors/join.cc | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 446585f0003..cb7c6c8b5b7 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -2528,7 +2528,7 @@ namespace views
 	  constexpr _Iterator&
 	  operator++()
 	  {
-	    auto&& __inner_range = [this] () -> decltype(auto) {
+	    auto&& __inner_range = [this] () -> auto&& {
 	      if constexpr (_S_ref_is_glvalue)
 		return *_M_outer;
 	      else
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
index 8bbea9a6b25..9c0231b704b 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
@@ -149,6 +149,16 @@ test08()
   VERIFY( i->a == 5 );
 }
 
+void
+test10()
+{
+  // PR libstdc++/100290
+  auto v = views::single(0)
+    | views::transform([](const auto& s) { return views::single(s); })
+    | views::join;
+  VERIFY( ranges::next(v.begin()) == v.end() );
+}
+
 int
 main()
 {
@@ -160,4 +170,5 @@ main()
   test06();
   test07();
   test08();
+  test10();
 }


                 reply	other threads:[~2021-05-03 20:10 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=20210503201017.B6FB73943541@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).