This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/85828] New: std::shuffle tries to swap element with itself
- From: "soap at gentoo dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 18 May 2018 12:45:34 +0000
- Subject: [Bug libstdc++/85828] New: std::shuffle tries to swap element with itself
- Auto-submitted: auto-generated
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.