public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3386] libstdc++: Fix typo in stride_view's operator- [PR107313]
@ 2022-10-19 17:04 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2022-10-19 17:04 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

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

commit r13-3386-ga10d6b5eb999a74fd4b12c00e8fb379cd3460e93
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Oct 19 13:03:25 2022 -0400

    libstdc++: Fix typo in stride_view's operator- [PR107313]
    
            PR libstdc++/107313
    
    libstdc++-v3/ChangeLog:
    
            * include/std/ranges (stride_view::_Iterator::operator-): Fix typo.
            * testsuite/std/ranges/adaptors/stride/1.cc (test03): New test.

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

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index d113cf19dc7..b29264931cc 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -7874,7 +7874,7 @@ namespace views::__adaptor
     friend constexpr difference_type
     operator-(default_sentinel_t __y, const _Iterator& __x)
       requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<_Base>>
-    { return __detail::__div_ceil(__x._M_end, __x._M_current, __x._M_stride); }
+    { return __detail::__div_ceil(__x._M_end - __x._M_current, __x._M_stride); }
 
     friend constexpr difference_type
     operator-(const _Iterator& __x, default_sentinel_t __y)
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/stride/1.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/stride/1.cc
index 745d1a61c1b..37ae896014a 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/stride/1.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/stride/1.cc
@@ -64,10 +64,30 @@ test02()
   VERIFY( ranges::equal(v, (int[]){1, 4, 7}) );
 }
 
+void
+test03()
+{
+  // PR libstdc++/107313
+  int x[] = {1, 2, 3, 4, 5};
+  __gnu_test::test_input_range<int> rx(x);
+  auto r = views::counted(rx.begin(), 4) | views::stride(2);
+  auto i = r.begin();
+  std::default_sentinel_t s = r.end();
+  VERIFY( s != i );
+  VERIFY( s - i == 2 && i - s == -2 );
+  ++i;
+  VERIFY( s != i );
+  VERIFY( s - i == 1 && i - s == -1 );
+  ++i;
+  VERIFY( s == i );
+  VERIFY( s - i == 0 && i - s == 0 );
+}
+
 int
 main()
 {
   static_assert(test01());
   test02<__gnu_test::test_input_range<int>>();
   test02<__gnu_test::test_forward_range<int>>();
+  test03();
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-19 17:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-19 17:04 [gcc r13-3386] libstdc++: Fix typo in stride_view's operator- [PR107313] 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).