[Bug libstdc++/125878] Some search algorithms form <algorithm> called with execution policies fail to produce correct result.

gaspar_pm at proton dot me gcc-bugzilla@gcc.gnu.org
Fri Jun 19 11:12:39 GMT 2026


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125878

--- Comment #1 from gaspar <gaspar_pm at proton dot me> ---
The only reasonable case when this isn't actually a bug is that the algorithms
pass iterators to the predicate interchangably - not always [first1, last1)
iterators as first argument and [first2, last2) iterators as second argument.

But looking at here: https://cppreference.com/cpp/algorithm/find_end

The declaration of the find_end overload I uses is this:
template< class ExecutionPolicy,
          class ForwardIt1, class ForwardIt2, class BinaryPred >
ForwardIt1 find_end( ExecutionPolicy&& policy,
                     ForwardIt1 first1, ForwardIt1 last1,
                     ForwardIt2 first2, ForwardIt2 last2,
                     BinaryPred p );

And the predicate is described like this:
> binary predicate which returns ​true if the elements should be treated as equal.
> The signature of the predicate function should be equivalent to the following:
> 
> bool pred(const Type1 &a, const Type2 &b);
> 
> While the signature does not need to have const &, the function must not modify the objects passed to it and must be able to accept all values of type (possibly const) Type1 and Type2 regardless of value category (thus, Type1 & is not allowed, nor is Type1 unless for Type1 a move is equivalent to a copy(since C++11)).
> The types Type1 and Type2 must be such that objects of types ForwardIt1 and ForwardIt2 can be dereferenced and then implicitly converted to Type1 and Type2 respectively.​

So I think the intended behaviour was that [first1, last1) iterators must
always be passed as first argument and [first2, last2) iterators must always be
passed as second argument to the predicate.


More information about the Gcc-bugs mailing list