https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101274
Bug ID: 101274 Summary: std::execution::seq has incorrect behaviour under GCC 11.1.0 Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: general at yhf8377 dot me Target Milestone: --- Created attachment 51091 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51091&action=edit Minimal code to reproduce the error We have a unit test that passes when compiled with GCC 10 but fails when compiled with GCC 11. Further digging shows that calling `std::reduce()` with execution policy `std::execution::seq` does not execute the provided function object in sequential order. Attached is the minimal test case that shows the different behaviour under GCC 10 and GCC 11. Under GCC 10 (10.3.0) the output is: plus_squared_ignore_nan: a = nan, b = 336.88 plus_squared_ignore_nan: a = 113488, b = nan plus_squared_ignore_nan: a = 113488, b = 818.6 plus_squared_ignore_nan: a = 783594, b = nan plus_squared_ignore_nan: a = 783594, b = 521.16 plus_squared_ignore_nan: a = 1.0552e+06, b = 451.78 plus_squared_ignore_nan: a = 1.25931e+06, b = 601.78 plus_squared_ignore_nan: a = 1.62145e+06, b = 709.2 plus_squared_ignore_nan: a = 2.12441e+06, b = 262.55 plus_squared_ignore_nan: a = 2.19334e+06, b = 659.67 plus_squared_ignore_nan: a = 2.62851e+06, b = 56.6 plus_squared_ignore_nan: a = 2.63171e+06, b = 780.31 plus_squared_ignore_nan: a = 3.2406e+06, b = 398.74 Correct! sum_squared == 3399588.6719 Under GCC 11 (11.1.0) the output is: plus_squared_ignore_nan: a = 336.88, b = nan plus_squared_ignore_nan: a = 818.6, b = nan plus_squared_ignore_nan: a = 336.88, b = 818.6 plus_squared_ignore_nan: a = nan, b = 670443 plus_squared_ignore_nan: a = 521.16, b = 451.78 plus_squared_ignore_nan: a = 601.78, b = 709.2 plus_squared_ignore_nan: a = 204626, b = 503566 plus_squared_ignore_nan: a = 4.49494e+11, b = 2.53579e+11 plus_squared_ignore_nan: a = 262.55, b = 659.67 plus_squared_ignore_nan: a = 56.6, b = 780.31 plus_squared_ignore_nan: a = 435427, b = 608940 plus_squared_ignore_nan: a = 6.43025e+22, b = 3.70809e+11 plus_squared_ignore_nan: a = 2.01802e+23, b = 398.74 gcc_test: src/main.cpp:24: int main(int, char**): Assertion `sum_squared == 3399588.6719' failed. Aborted