<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - random_shuffle swaps elements with themselves"
   href="https://bugs.llvm.org/show_bug.cgi?id=38900">38900</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>random_shuffle swaps elements with themselves
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>7.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>tdhutt@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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:

<a href="https://github.com/llvm-mirror/libcxx/blob/ed6c20e48d547bdda5c68ba1b8f79a16916683ab/include/algorithm#L2989">https://github.com/llvm-mirror/libcxx/blob/ed6c20e48d547bdda5c68ba1b8f79a16916683ab/include/algorithm#L2989</a>

I would do a pull request but it looks like you are still using SVN...</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>