oneapi-src / oneDPL

oneAPI DPC++ Library (oneDPL) https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/dpc-library.html
Apache License 2.0
725 stars 113 forks source link

Numeric PSTL algos require copy-constructible #1955

Open jwakely opened 1 day ago

jwakely commented 1 day ago

All of reduce, transform_reduce, exclusive_scan, and inclusive_scan, transform_exclusive_scan, and transform_inclusive_scan only have a precondition on the type of init that it meets the Cpp17MoveConstructible requirements, so when passing it to the next internal function it needs to be moved, not copied:

     return transform_inclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __binary_op,
-                                    __pstl::__internal::__no_op(), __init);
+                                    __pstl::__internal::__no_op(), std::move(__init));

And they need to move when creating local variables:

-        _Tp __temp = *__first;
+        _Tp __temp = std::move(*__first);

and when returning init as well:

-    return std::make_pair(__result, __init);
+    return std::make_pair(__result, std::move(__init));

https://github.com/oneapi-src/oneDPL/blame/b132b83cddec63df5b3794aba8c154cb186d568e/include/oneapi/dpl/pstl/numeric_impl.h#L176-L182

jwakely commented 1 day ago

Also reported as https://github.com/llvm/llvm-project/issues/118539 and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117905