[libcxx-commits] [libcxx] [libc++] Fix random_shuffle in __cxx03/__algorithm/shuffle.h (PR #186434)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 13 09:12:34 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- libcxx/test/std/algorithms/alg.sorting/alg.random.shuffle/random.shuffle.funcptr.compile.pass.cpp libcxx/include/__cxx03/__algorithm/shuffle.h --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.random.shuffle/random.shuffle.funcptr.compile.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.random.shuffle/random.shuffle.funcptr.compile.pass.cpp
index 7a0b08f77..5c6d18d32 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.random.shuffle/random.shuffle.funcptr.compile.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.random.shuffle/random.shuffle.funcptr.compile.pass.cpp
@@ -24,21 +24,19 @@ typedef std::iterator_traits<Iter>::difference_type Diff;
 typedef Diff (*RandomNumberGenerator)(Diff);
 
 // Wrapper that calls the legacy random_shuffle overload with RNG by reference.
-void f(Iter a1, Iter a2, RandomNumberGenerator& a3) {
-    std::random_shuffle<Iter, RandomNumberGenerator>(a1, a2, a3);
-}
+void f(Iter a1, Iter a2, RandomNumberGenerator& a3) { std::random_shuffle<Iter, RandomNumberGenerator>(a1, a2, a3); }
 
 // A minimal RNG with the required signature. Behavior doesn't matter for compile test.
 static Diff rng(Diff n) {
-    return (n <= 1) ? 0 : (n - 1); // returns in [0, n)
+  return (n <= 1) ? 0 : (n - 1); // returns in [0, n)
 }
 
 int main() {
-    // Use a C array to avoid C++11 initializer_list; this is valid in C++03.
-    int data[] = {0, 1, 2, 3, 4};
-    std::vector<int> v(data, data + sizeof(data)/sizeof(data[0]));
+  // Use a C array to avoid C++11 initializer_list; this is valid in C++03.
+  int data[] = {0, 1, 2, 3, 4};
+  std::vector<int> v(data, data + sizeof(data) / sizeof(data[0]));
 
-    RandomNumberGenerator g = &rng;
-    f(v.begin(), v.end(), g);
-    return 0;
+  RandomNumberGenerator g = &rng;
+  f(v.begin(), v.end(), g);
+  return 0;
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/186434


More information about the libcxx-commits mailing list