]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix constraint recursion in basic_const_iterator relops [PR112490]
authorPatrick Palka <ppalka@redhat.com>
Fri, 28 Feb 2025 14:39:57 +0000 (09:39 -0500)
committerPatrick Palka <ppalka@redhat.com>
Fri, 28 Feb 2025 14:39:57 +0000 (09:39 -0500)
commit4342c50ca84ae5448c0128c52120f4fe9005f203
treeb79ebb03ca9c264ccfd479005464af5570d0c1dc
parent7eb8ec1856f71b039d1c2235b1c941934fa28e22
libstdc++: Fix constraint recursion in basic_const_iterator relops [PR112490]

Here for

  using RCI = reverse_iterator<basic_const_iterator<vector<int>::iterator>>
  static_assert(std::totally_ordered<RCI>);

we effectively need to check the requirement

  requires (RCI x) { x RELOP x; }  for each RELOP in {<, >, <=, >=}

which we expect to be straightforwardly satisfied by reverse_iterator's
namespace-scope relops.  But due to ADL we find ourselves also
considering the basic_const_iterator relop friends, which before CWG
2369 would be quickly discarded since RCI clearly isn't convertible to
basic_const_iterator.  After CWG 2369 though we must first check these
relops' constraints (with _It = vector<int>::iterator and _It2 = RCI),
which entails checking totally_ordered<RCI> recursively.

This patch fixes this by turning the problematic non-dependent function
parameters of type basic_const_iterator<_It> into dependent ones of
type basic_const_iterator<_It3> where _It3 is constrained to match _It.
Thus the basic_const_iterator relop friends now get quickly discarded
during deduction and before the constraint check if the second operand
isn't a specialization of basic_const_iterator (or derived from one)
like before CWG 2369.

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<_It3> where _It3
matches _It.
(basic_const_iterator::operator>): Likewise.
(basic_const_iterator::operator<=): Likewise.
(basic_const_iterator::operator>=): Likewise.
* testsuite/24_iterators/const_iterator/112490.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/include/bits/stl_iterator.h
libstdc++-v3/testsuite/24_iterators/const_iterator/112490.cc [new file with mode: 0644]