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: unassignedclangb...@nondot.org
          Reporter: tdh...@gmail.com
                CC: llvm-bugs@lists.llvm.org, mclow.li...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to