public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-9907] libstdc++: Fix access issue in iota_view::_Sentinel [PR100690]
@ 2021-06-10 19:25 Patrick Palka
0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2021-06-10 19:25 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:8f5cda0e646822bbd01e642ed28a4f4f0cca8c59
commit r10-9907-g8f5cda0e646822bbd01e642ed28a4f4f0cca8c59
Author: Patrick Palka <ppalka@redhat.com>
Date: Thu May 20 23:39:05 2021 -0400
libstdc++: Fix access issue in iota_view::_Sentinel [PR100690]
libstdc++-v3/ChangeLog:
PR libstdc++/100690
* include/std/ranges (iota_view::_Sentinel::_M_distance_from):
Split out this member function from ...
(iota_view::_Sentinel::operator-): ... here, for sake of access
control.
* testsuite/std/ranges/iota/iota_view.cc (test05): New test.
(cherry picked from commit 317a38cd468d565dc8ce45c6da0dbccf38808f70)
Diff:
---
libstdc++-v3/include/std/ranges | 8 ++++++--
libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc | 11 +++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index c69a44f2ed8..907f2824bbe 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -816,6 +816,10 @@ namespace ranges
_M_equal(const _Iterator& __x) const
{ return __x._M_value == _M_bound; }
+ constexpr auto
+ _M_distance_from(const _Iterator& __x) const
+ { return _M_bound - __x._M_value; }
+
_Bound _M_bound = _Bound();
public:
@@ -832,12 +836,12 @@ namespace ranges
friend constexpr iter_difference_t<_Winc>
operator-(const _Iterator& __x, const _Sentinel& __y)
requires sized_sentinel_for<_Bound, _Winc>
- { return __x._M_value - __y._M_bound; }
+ { return -__y._M_distance_from(__x); }
friend constexpr iter_difference_t<_Winc>
operator-(const _Sentinel& __x, const _Iterator& __y)
requires sized_sentinel_for<_Bound, _Winc>
- { return -(__y - __x); }
+ { return __x._M_distance_from(__y); }
};
_Winc _M_value = _Winc();
diff --git a/libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc b/libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc
index 65d166fbd3b..76888ac7959 100644
--- a/libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc
+++ b/libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc
@@ -77,6 +77,16 @@ test04()
VERIFY( it == v.end() );
}
+void
+test05()
+{
+ // PR libstdc++/100690
+ int x[] = {42, 42, 42};
+ auto r = std::views::iota(std::ranges::begin(x), std::ranges::cbegin(x) + 3);
+ VERIFY( r.end() - r.begin() == 3 );
+ VERIFY( r.begin() - r.end() == -3 );
+}
+
int
main()
{
@@ -84,4 +94,5 @@ main()
test02();
test03();
test04();
+ test05();
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-06-10 19:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-10 19:25 [gcc r10-9907] libstdc++: Fix access issue in iota_view::_Sentinel [PR100690] Patrick Palka
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).