]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add deprecated attribute to std::random_shuffle declarations
authorJonathan Wakely <jwakely@redhat.com>
Wed, 26 Jul 2023 13:05:58 +0000 (14:05 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 18 Mar 2024 13:50:45 +0000 (13:50 +0000)
We already have these attributes on the definitions in <bits/stl_algo.h>
but they don't work due to PR c++/84542. Add the attributes to the
declarations in <bits/algorithmfwd.h> as well, and add a test.

libstdc++-v3/ChangeLog:

* include/bits/algorithmfwd.h (random_shuffle): Add deprecated
attribute.
* include/bits/stl_algo.h (random_shuffle): Correct comments.
* testsuite/25_algorithms/random_shuffle/1.cc: Disable
deprecated warnings.
* testsuite/25_algorithms/random_shuffle/59603.cc: Likewise.
* testsuite/25_algorithms/random_shuffle/moveable.cc: Likewise.
* testsuite/25_algorithms/random_shuffle/deprecated.cc: New
test.

(cherry picked from commit c01b344e814001e07fd304ce98d013d811e90192)

libstdc++-v3/include/bits/algorithmfwd.h
libstdc++-v3/include/bits/stl_algo.h
libstdc++-v3/testsuite/25_algorithms/random_shuffle/1.cc
libstdc++-v3/testsuite/25_algorithms/random_shuffle/59603.cc
libstdc++-v3/testsuite/25_algorithms/random_shuffle/deprecated.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc

index 5271a90b50154e98446bd206e3085880aac1926d..5b85b0bc60dc92f518e3d2096c14ea9cf0dc2d09 100644 (file)
@@ -828,10 +828,12 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
     partition(_BIter, _BIter, _Predicate);
 
   template<typename _RAIter>
+    _GLIBCXX14_DEPRECATED_SUGGEST("std::shuffle")
     void
     random_shuffle(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Generator>
+    _GLIBCXX14_DEPRECATED_SUGGEST("std::shuffle")
     void
     random_shuffle(_RAIter, _RAIter,
 #if __cplusplus >= 201103L
index 1f07b9e65897da10b1548f5989a72a2f250d6296..41a8cf2f3e18e077d3f1e01a4844b8ef8f7fcd8d 100644 (file)
@@ -4532,7 +4532,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
    *  equally likely.
    *
    *  @deprecated
-   *  Since C++14 `std::random_shuffle` is not part of the C++ standard.
+   *  Since C++17, `std::random_shuffle` is not part of the C++ standard.
    *  Use `std::shuffle` instead, which was introduced in C++11.
   */
   template<typename _RandomAccessIterator>
@@ -4572,7 +4572,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
    *  range [0,N).
    *
    *  @deprecated
-   *  Since C++14 `std::random_shuffle` is not part of the C++ standard.
+   *  Since C++17, `std::random_shuffle` is not part of the C++ standard.
    *  Use `std::shuffle` instead, which was introduced in C++11.
   */
   template<typename _RandomAccessIterator, typename _RandomNumberGenerator>
index fd1f5eb0717e0b483d95575848aa1b47f953d140..37814f695c67e2da10a268de10759341b54c9e6a 100644 (file)
@@ -15,6 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+// { dg-options "-Wno-deprecated-declarations" }
 // { dg-add-options using-deprecated }
 
 // 25.2.11 random_shuffle()
index d5ef0725036f4b8b311592b2ca46cc156508f259..3a31dd12da0cab99b613440132430f7eec33bf12 100644 (file)
@@ -16,6 +16,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do run { target c++11 } }
+// { dg-options "-Wno-deprecated-declarations" }
 // { dg-add-options using-deprecated }
 // { dg-require-debug-mode "" }
 
diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/deprecated.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/deprecated.cc
new file mode 100644 (file)
index 0000000..48fc5b0
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-do compile }
+// { dg-add-options using-deprecated }
+
+// std::random_shuffle was deprecated in C++17 and removed in C++17.
+
+#include <algorithm>
+
+std::ptrdiff_t rando(std::ptrdiff_t n);
+
+void
+test_depr(int* first, int* last)
+{
+  std::random_shuffle(first, last);
+  // { dg-warning "deprecated" "" { target c++14 } 13 }
+
+  std::random_shuffle(first, last, rando);
+  // { dg-warning "deprecated" "" { target c++14 } 16 }
+}
index d72906828d0328402b4d3090ab7548666784e0c7..18f6de40c69dd7244c2a6800ebd76ec00a2882db 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do run { target c++11 } }
+// { dg-options "-Wno-deprecated-declarations" }
 // { dg-add-options using-deprecated }
 
 // Copyright (C) 2009-2022 Free Software Foundation, Inc.