[Bug libstdc++/85828] New: std::shuffle tries to swap element with itself
soap at gentoo dot org
gcc-bugzilla@gcc.gnu.org
Fri May 18 12:45:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85828
Bug ID: 85828
Summary: std::shuffle tries to swap element with itself
Product: gcc
Version: 7.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: soap at gentoo dot org
Target Milestone: ---
This bug is related to a previous one in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59603. For a full description, see
https://stackoverflow.com/questions/22915325/avoiding-self-assignment-in-stdshuffle.
The problem boils down to the fact that in std::shuffle, self-assignment in
some std::swap(x, x) will happen eventually. This will cause an "Error: attempt
to self move assign." failure to occur and kill the program when compiled in
debug mode. A chat on IRC with Jonathan Wakely confirmed that this is an
implementation bug, and that the likely correct fix for this is to avoid
self-swap in std::shuffle.
More information about the Gcc-bugs
mailing list