Skip to content

Commit d2e2688

Browse files
author
Patrick Palka
committed
libstdc++: Fix constraint recursion in basic_const_iterator operator- [PR115046]
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 <[email protected]> (cherry picked from commit d69f73c)
1 parent 573422d commit d2e2688

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

libstdc++-v3/include/bits/stl_iterator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,10 +2928,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
29282928
noexcept(noexcept(_M_current - __y))
29292929
{ return _M_current - __y; }
29302930

2931-
template<__detail::__not_a_const_iterator _Sent>
2931+
template<__detail::__not_a_const_iterator _Sent, same_as<_It> _It2>
29322932
requires sized_sentinel_for<_Sent, _It>
29332933
friend constexpr difference_type
2934-
operator-(const _Sent& __x, const basic_const_iterator& __y)
2934+
operator-(const _Sent& __x, const basic_const_iterator<_It2>& __y)
29352935
noexcept(noexcept(__x - __y._M_current))
29362936
{ return __x - __y._M_current; }
29372937

libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,23 @@ test03()
6868
auto r2 = views::as_const(views::all(v));
6969
}
7070

71+
void
72+
test04()
73+
{
74+
// PR libstdc++/115046 - meta-recursion with join_view and as_const_view
75+
int x[3] = {1,2,3};
76+
auto v = x
77+
| views::chunk(3)
78+
| views::transform(views::as_const)
79+
| views::join;
80+
VERIFY( ranges::equal(v, x) );
81+
}
82+
7183
int
7284
main()
7385
{
7486
static_assert(test01());
7587
static_assert(test02());
7688
test03();
89+
test04();
7790
}

0 commit comments

Comments
 (0)