<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 - std::shuffle() hangs with clang but works well with gcc/msvs"
   href="https://bugs.llvm.org/show_bug.cgi?id=49621">49621</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::shuffle() hangs with clang but works well with gcc/msvs
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>yury.norov@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, mikkqu@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Confirmed on Linux and Mac. Discovered with Michail Kalashnikov.

clang -v
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/

Reproducer: <a href="https://rextester.com/ZMML24952">https://rextester.com/ZMML24952</a>

#include <iostream>
#include <vector>
#include <algorithm>
#include <random>

using namespace std;

int shuffler_fn(int i) {
    //cout << "Shuffler: " << i << endl;
    return std::rand() % i;
}

void random_shuffle() {
    vector<int> rows{1, 2, 3, 4, 5, 6, 7, 8, 9, 0};

    std::random_shuffle(rows.begin(), rows.end(), shuffler_fn);

    for (const auto& item : rows) {
        cout << item << ' ';
    }
}

class Shuffler {
public:
  typedef int result_type;
  static constexpr int min() { return 0; }
  static constexpr int max() { return RAND_MAX; }

  int operator()() const { return std::rand(); }
};

void just_shuffle() {
    vector<int> rows{1, 2, 3, 4, 5, 6, 7, 8, 9, 0};

    Shuffler shuffler;

    std::shuffle(rows.begin(), rows.end(), shuffler);

    for (const auto& item : rows) {
        cout << item << ' ';
    }
}

int main()
{
    random_shuffle();
    cout << endl;
    just_shuffle();
    cout << endl;
    return 0;
}</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>