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

Zibi Sarbinowski via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 28 13:19:45 PDT 2025


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

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.


>From d76229eb025d702d22c61b7b9a7f9336c4385ad9 Mon Sep 17 00:00:00 2001
From: Zibi Sarbinowski <zibi at ca.ibm.com>
Date: Thu, 28 Aug 2025 20:14:34 +0000
Subject: [PATCH] Fix random_shuffle in __cxx03/__algorithm/shuffle.h

---
 libcxx/include/__cxx03/__algorithm/shuffle.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__cxx03/__algorithm/shuffle.h b/libcxx/include/__cxx03/__algorithm/shuffle.h
index fee7028ae22aca..24cd71c71378ba 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) {



More information about the libcxx-commits mailing list