]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix handling iterators with proxy subscript in heap algorithms.
authorTomasz Kamiński <tkaminsk@redhat.com>
Tue, 13 Jan 2026 15:29:42 +0000 (16:29 +0100)
committerTomasz Kamiński <tkaminsk@redhat.com>
Tue, 13 Jan 2026 18:14:26 +0000 (19:14 +0100)
commit76ad28b11266606fcc1571d0ef92d3f2ef402bfb
tree05c349a38f424a9bf4c6401e4fd59a6aa79b649e
parent17582084fad3a0fbf72a83524a4100d2eb802107
libstdc++: Fix handling iterators with proxy subscript in heap algorithms.

This patch replaces uses of subscripts in heap algorithms, that where introduced
in r16-4100-gaaeca77a79a9a8 with dereference of advanced iterators.

The Cpp17RandomAccessIterator requirements, allows operator[] to return any
type that is convertible to reference, however user-provided comparators are
required only to accept result of dereferencing the iterator (i.e. reference
directly). This is visible, when comparator defines operator() for which
template arguments can be deduduced from reference (which will fail on proxy)
or that accepts types convertible from reference (see included tests).

For test we introduce a new proxy_random_access_iterator_wrapper iterator
in testsuite_iterators.h, that returns a proxy type from subscript operator.
This is separate type (instead of additional template argument and aliases),
as it used for test that work with C++98.

libstdc++-v3/ChangeLog:

* include/bits/stl_heap.h (std::__is_heap_until, std::__push_heap)
(std::__adjust_heap): Replace subscript with dereference of
advanced iterator.
* testsuite/util/testsuite_iterators.h (__gnu_test::subscript_proxy)
(__gnu_test::proxy_random_access_iterator_wrapper): Define.
* testsuite/25_algorithms/sort_heap/check_proxy_brackets.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
libstdc++-v3/include/bits/stl_heap.h
libstdc++-v3/testsuite/25_algorithms/sort_heap/check_proxy_brackets.cc [new file with mode: 0644]
libstdc++-v3/testsuite/util/testsuite_iterators.h