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

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 28 13:20:17 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Zibi Sarbinowski (zibi2)

<details>
<summary>Changes</summary>

Before the change a declaration in question was like the following:
```
template <class _RandomAccessIterator, class _RandomNumberGenerator>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX14 void
random_shuffle(_RandomAccessIterator __first,
               _RandomAccessIterator __last,
#  ifndef _LIBCPP_CXX03_LANG
               _RandomNumberGenerator&& __rand)
#  else
               _RandomNumberGenerator& __rand)
#  endif
```
The frozen cxx03 header should use reference for the 3rd parameter of `random_shuffle()` template function.


---
Full diff: https://github.com/llvm/llvm-project/pull/155915.diff


1 Files Affected:

- (modified) libcxx/include/__cxx03/__algorithm/shuffle.h (+1-1) 


``````````diff
diff --git a/libcxx/include/__cxx03/__algorithm/shuffle.h b/libcxx/include/__cxx03/__algorithm/shuffle.h
index fee7028ae22ac..24cd71c71378b 100644
--- a/libcxx/include/__cxx03/__algorithm/shuffle.h
+++ b/libcxx/include/__cxx03/__algorithm/shuffle.h
@@ -109,7 +109,7 @@ _LIBCPP_HIDE_FROM_ABI void random_shuffle(_RandomAccessIterator __first, _Random
 
 template <class _RandomAccessIterator, class _RandomNumberGenerator>
 _LIBCPP_HIDE_FROM_ABI void
-random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, _RandomNumberGenerator&& __rand) {
+random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, _RandomNumberGenerator& __rand) {
   typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
   difference_type __d = __last - __first;
   if (__d > 1) {

``````````

</details>


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


More information about the libcxx-commits mailing list