public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-2567] libstdc++: Fix zip_view's operator- for integer-class difference type [PR106766]
@ 2022-09-09 19:04 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2022-09-09 19:04 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:718a6d475b3d17759618c68331c85f55c58ec9a3

commit r13-2567-g718a6d475b3d17759618c68331c85f55c58ec9a3
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Sep 9 14:56:32 2022 -0400

    libstdc++: Fix zip_view's operator- for integer-class difference type [PR106766]
    
    The difference type of an underlying iterator could be an integer-class
    type, which make_unsigned_t doesn't handle, so we need to use the more
    general __make_unsigned_like_t / __to_unsigned_like here instead.
    
            PR libstdc++/106766
    
    libstdc++-v3/ChangeLog:
    
            * include/std/ranges (zip_view::_Iterator::operator-): Use
            __to_unsigned_like instead of make_unsigned_t.
            (zip_view::_Sentinel::operator-): Likewise.
            * testsuite/std/ranges/zip/1.cc (test04): New test.

Diff:
---
 libstdc++-v3/include/std/ranges            |  8 ++++----
 libstdc++-v3/testsuite/std/ranges/zip/1.cc | 18 ++++++++++++++++++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 2b5cb0531f0..2b8fec3c386 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -4657,8 +4657,8 @@ namespace views::__adaptor
 	return ranges::min({difference_type(std::get<_Is>(__x._M_current)
 					    - std::get<_Is>(__y._M_current))...},
 			   ranges::less{},
-			   [](difference_type __i) -> make_unsigned_t<difference_type> {
-			     return __i < 0 ? -__i : __i;
+			   [](difference_type __i) {
+			     return __detail::__to_unsigned_like(__i < 0 ? -__i : __i);
 			   });
       }(make_index_sequence<sizeof...(_Vs)>{});
     }
@@ -4726,8 +4726,8 @@ namespace views::__adaptor
       return [&]<size_t... _Is>(index_sequence<_Is...>) {
 	return ranges::min({_Ret(std::get<_Is>(__x._M_current) - std::get<_Is>(__y._M_end))...},
 			   ranges::less{},
-			   [](_Ret __i) -> make_unsigned_t<_Ret> {
-			     return __i < 0 ? -__i : __i;
+			   [](_Ret __i) {
+			     return __detail::__to_unsigned_like(__i < 0 ? -__i : __i);
 			   });
       }(make_index_sequence<sizeof...(_Vs)>{});
     }
diff --git a/libstdc++-v3/testsuite/std/ranges/zip/1.cc b/libstdc++-v3/testsuite/std/ranges/zip/1.cc
index 0113efdb537..e9e40fb15eb 100644
--- a/libstdc++-v3/testsuite/std/ranges/zip/1.cc
+++ b/libstdc++-v3/testsuite/std/ranges/zip/1.cc
@@ -102,10 +102,28 @@ test03()
   return true;
 }
 
+constexpr bool
+test04()
+{
+  // PR libstdc++/106766
+#if __SIZEOF_INT128__
+  auto r = views::zip(views::iota(__int128(0), __int128(1)));
+#else
+  auto r = views::zip(views::iota(0ll, 1ll));
+#endif
+  auto i = r.begin();
+  auto s = r.end();
+  VERIFY( s - i == 1 );
+  VERIFY( i + 1 - i == 1 );
+
+  return true;
+}
+
 int
 main()
 {
   static_assert(test01());
   static_assert(test02());
   static_assert(test03());
+  static_assert(test04());
 }

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

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

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-09 19:04 [gcc r13-2567] libstdc++: Fix zip_view's operator- for integer-class difference type [PR106766] 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).