@@ -410,7 +410,9 @@ struct __contains_fn
410410 bool
411411 operator ()(_ExecutionPolicy&& __exec, _R&& __r, const _T& __value, _Proj __proj = {}) const
412412 {
413- return oneapi::dpl::ranges::find (std::forward<_ExecutionPolicy>(__exec), __r, __value, __proj) != std::ranges::end (__r);
413+ // To ensure no dangling pointer is returned, __r may not be forwarded
414+ return oneapi::dpl::ranges::find (std::forward<_ExecutionPolicy>(__exec), __r, __value, __proj)
415+ != std::ranges::end (__r);
414416 }
415417}; // __contains_fn
416418
@@ -426,9 +428,9 @@ struct __contains_subrange_fn
426428 operator ()(_ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _Pred __pred = {}, _Proj1 __proj1 = {},
427429 _Proj2 __proj2 = {}) const
428430 {
429- return __r2. size () == 0 ||
430- ! oneapi::dpl::ranges::search (std::forward<_ExecutionPolicy>(__exec), std::forward<_R1>( __r1) ,
431- std::forward<_R2>(__r2), __pred, __proj1, __proj2).empty ();
431+ // To ensure no dangling subrange is returned, __r1 may not be forwarded
432+ return __r2. size () == 0 || ! oneapi::dpl::ranges::search (std::forward<_ExecutionPolicy>(__exec), __r1, __r2 ,
433+ __pred, __proj1, __proj2).empty ();
432434 }
433435}; // __contains_subrange_fn
434436} // __internal
0 commit comments