libstdc++: Fix return value of std::ranges::advance [PR 100833]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 1 Jun 2021 15:02:45 +0000 (16:02 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 1 Jun 2021 16:09:06 +0000 (17:09 +0100)
commitd8326291695c0f13124c232ddf4fd34e3310e649
tree521c4f534780df37f10502876c963bc7bd7adc33
parentcf2b7020ee8e9745ede527b0a3b2e0ffbafd492b
libstdc++: Fix return value of std::ranges::advance [PR 100833]

The three-argument form of ranges::advance is supposed to return the
difference between the second argument and the distance the iterator was
advanced. When a non-random-access iterator is not advanced (because it
already equals the sentinel) we were returning 0 rather than n - 0.

libstdc++-v3/ChangeLog:

PR libstdc++/100833
* include/bits/ranges_base.h (ranges::advance(iter, n, sentinel)):
Fix return value for no-op case.
* testsuite/24_iterators/range_operations/advance.cc: Test
return values of three-argument overload.
libstdc++-v3/include/bits/ranges_base.h
libstdc++-v3/testsuite/24_iterators/range_operations/advance.cc