]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix constraint recursion in basic_const_iterator operator- [PR115046]
authorPatrick Palka <ppalka@redhat.com>
Wed, 9 Apr 2025 21:48:05 +0000 (17:48 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 27 May 2025 20:38:49 +0000 (16:38 -0400)
It was proposed in PR112490 to also adjust basic_const_iterator's friend
operator-(sent, iter) overload alongside the r15-7757-g4342c50ca84ae5
adjustments to its comparison operators, but we lacked a concrete
testcase demonstrating fixable constraint recursion there.  It turns out
Hewill Kang's PR115046 is such a testcase!  So this patch makes the same
adjustments to that overload as well, fixing PR115046.  The LWG 4218 P/R
will need to get adjusted too.

PR libstdc++/115046
PR libstdc++/112490

libstdc++-v3/ChangeLog:

* include/bits/stl_iterator.h (basic_const_iterator::operator-):
Replace non-dependent basic_const_iterator function parameter with
a dependent one of type basic_const_iterator<_It2> where _It2
matches _It.
* testsuite/std/ranges/adaptors/as_const/1.cc (test04): New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
(cherry picked from commit d69f73c0334486f3c66937388f02008736809e87)

libstdc++-v3/include/bits/stl_iterator.h
libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc

index f3ad2ebbb8f3d2346877bb145b84349d91ee2623..86fd5571b2eefd2a0225600aa894189c2896b013 100644 (file)
@@ -2928,10 +2928,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       noexcept(noexcept(_M_current - __y))
       { return _M_current - __y; }
 
-    template<__detail::__not_a_const_iterator _Sent>
+    template<__detail::__not_a_const_iterator _Sent, same_as<_It> _It2>
       requires sized_sentinel_for<_Sent, _It>
       friend constexpr difference_type
-      operator-(const _Sent& __x, const basic_const_iterator& __y)
+      operator-(const _Sent& __x, const basic_const_iterator<_It2>& __y)
       noexcept(noexcept(__x - __y._M_current))
       { return __x - __y._M_current; }
 
index 03814096fffc46a06b96f9659e28fe661df4ae11..0b8540e138dcfefab89cdd8a8ef04d1cab0a38b9 100644 (file)
@@ -68,10 +68,23 @@ test03()
     auto r2 = views::as_const(views::all(v));
 }
 
+void
+test04()
+{
+  // PR libstdc++/115046 - meta-recursion with join_view and as_const_view
+  int x[3] = {1,2,3};
+  auto v = x
+    | views::chunk(3)
+    | views::transform(views::as_const)
+    | views::join;
+  VERIFY( ranges::equal(v, x) );
+}
+
 int
 main()
 {
   static_assert(test01());
   static_assert(test02());
   test03();
+  test04();
 }