* [PATCH] libstdc++: Fix up lambda in join_view::_Iterator::operator++ [PR100290]
@ 2021-04-27 14:55 Patrick Palka
2021-04-27 15:44 ` Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2021-04-27 14:55 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++, Patrick Palka
Currently, the return type of this lambda is decltype(auto), so it ends
up returning a copy of _M_parent->_M_inner rather than a reference to it
when _S_ref_glvalue is false. Hence _M_inner and ranges::end(__inner_range)
are respectively an iterator and sentinel for different ranges, so
comparing them is undefined.
Tested on x86_64-pc-linux-gnu, does this look OK for trunk/11/10?
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.
---
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 74075a2d6d3..09115e9b45f 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -2389,7 +2389,7 @@ namespace views::__adaptor
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 fb06a7698af..e6c71d771de 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
@@ -160,6 +160,16 @@ test09()
static_assert(!requires { 0 | join; });
}
+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()
{
@@ -172,4 +182,5 @@ main()
test07();
test08();
test09();
+ test10();
}
--
2.31.1.362.g311531c9de
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] libstdc++: Fix up lambda in join_view::_Iterator::operator++ [PR100290]
2021-04-27 14:55 [PATCH] libstdc++: Fix up lambda in join_view::_Iterator::operator++ [PR100290] Patrick Palka
@ 2021-04-27 15:44 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2021-04-27 15:44 UTC (permalink / raw)
To: Patrick Palka; +Cc: gcc-patches, libstdc++
On 27/04/21 10:55 -0400, Patrick Palka via Libstdc++ wrote:
>Currently, the return type of this lambda is decltype(auto), so it ends
>up returning a copy of _M_parent->_M_inner rather than a reference to it
>when _S_ref_glvalue is false. Hence _M_inner and ranges::end(__inner_range)
>are respectively an iterator and sentinel for different ranges, so
>comparing them is undefined.
>
>Tested on x86_64-pc-linux-gnu, does this look OK for trunk/11/10?
Yes for all three, thanks.
>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.
>---
> 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 74075a2d6d3..09115e9b45f 100644
>--- a/libstdc++-v3/include/std/ranges
>+++ b/libstdc++-v3/include/std/ranges
>@@ -2389,7 +2389,7 @@ namespace views::__adaptor
> 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 fb06a7698af..e6c71d771de 100644
>--- a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
>+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
>@@ -160,6 +160,16 @@ test09()
> static_assert(!requires { 0 | join; });
> }
>
>+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()
> {
>@@ -172,4 +182,5 @@ main()
> test07();
> test08();
> test09();
>+ test10();
> }
>--
>2.31.1.362.g311531c9de
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-27 15:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-27 14:55 [PATCH] libstdc++: Fix up lambda in join_view::_Iterator::operator++ [PR100290] Patrick Palka
2021-04-27 15:44 ` Jonathan Wakely
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).