[llvm-bugs] [Bug 38900] New: random_shuffle swaps elements with themselves
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Sep 11 04:13:43 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=38900
Bug ID: 38900
Summary: random_shuffle swaps elements with themselves
Product: libc++
Version: 7.0
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: tdhutt at gmail.com
CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
The version of std::random_shuffle() that takes a custom PRNG can call swap(a,
a) (i.e. swap an element with itself.
I'd say that should be fine according to the standard but in practice some
things don't like this (in my cast Boost's small_vector) and so you randomly
get assertion failures which is rather annoying (I will submit a patch to Boost
for this too).
Anyway this should definitely be fixed - this bug existed in old versions of
libstdc++ but they fixed it. And more importantly the other versions of
std::random_shuffle, and std::shuffle have been fixed.
The fix is simple, just add
if (__i != difference_type(0))
Here:
https://github.com/llvm-mirror/libcxx/blob/ed6c20e48d547bdda5c68ba1b8f79a16916683ab/include/algorithm#L2989
I would do a pull request but it looks like you are still using SVN...
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180911/7fc285d6/attachment.html>
More information about the llvm-bugs
mailing list