The source comment: #2780 (comment)
This code is used from
struct __internal::__partial_sort_copy_fn
{
template <typename _ExecutionPolicy, std::ranges::random_access_range _R, std::ranges::random_access_range _OutR,
typename _Comp = std::ranges::less, typename _Proj1 = std::identity, typename _Proj2 = std::identity>
requires oneapi::dpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
std::ranges::sized_range<_R> && std::ranges::sized_range<_OutR> &&
std::indirectly_copyable<std::ranges::iterator_t<_R>, std::ranges::iterator_t<_OutR>> &&
std::sortable<std::ranges::iterator_t<_OutR>, _Comp, _Proj2> &&
std::indirect_strict_weak_order<_Comp, std::projected<std::ranges::iterator_t<_R>, _Proj1>,
std::projected<std::ranges::iterator_t<_OutR>, _Proj2>>
std::ranges::partial_sort_copy_result<std::ranges::borrowed_iterator_t<_R>, std::ranges::borrowed_iterator_t<_OutR>>
operator()(_ExecutionPolicy&& __exec, _R&& __r, _OutR&& __result, _Comp __comp = {}, _Proj1 __proj1 = {},
_Proj2 __proj2 = {}) const
{
const auto __dispatch_tag = oneapi::dpl::__ranges::__select_backend(__exec);
return oneapi::dpl::__internal::__ranges::__pattern_partial_sort_copy_ranges(
__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r),
std::forward<_OutR>(__result), __comp, __proj1, __proj2);
}
}; //__partial_sort_copy_fn
inline constexpr __internal::__partial_sort_copy_fn partial_sort_copy;
std::indirectly_copyable<std::ranges::iterator_t<_R>, std::ranges::iterator_t<_OutR>> check in the requires clause permits copy assignment, but it does not inherently allow copy via the constructor in placement new, which is used in the implementation.
The classic partial_sort_copy is also prone to this issue, because it only has an indirectly_copyable-like requirement in the standard:
*first must be writable to d_first
oneDPL/include/oneapi/dpl/pstl/algorithm_impl.h
Line 2577 in e16a913
The source comment: #2780 (comment)
This code is used from
std::indirectly_copyable<std::ranges::iterator_t<_R>, std::ranges::iterator_t<_OutR>>check in therequiresclause permits copy assignment, but it does not inherently allow copy via the constructor inplacement new, which is used in the implementation.The classic
partial_sort_copyis also prone to this issue, because it only has an indirectly_copyable-like requirement in the standard: