]> 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>
Wed, 26 Jul 2023 16:02:46 +0000 (17:02 +0100)
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.

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 0d623901cd2db121472410965970abe1346406ab..130943d23406b46f28cfbe92d445efc3abb7b9ed 100644 (file)
@@ -832,10 +832,12 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
 
 #if _GLIBCXX_HOSTED
   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 2c52ed5140269d829670736c7f2f7419236a1204..3abf0f69d468458f9b3b0e8f9a6b57a7dc05c2f8 100644 (file)
@@ -4479,7 +4479,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>
@@ -4518,7 +4518,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>
@@ -4546,7 +4546,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
        }
     }
 #endif // HOSTED
-#endif // C++11 || USE_DEPRECATED
+#endif // <= C++11 || USE_DEPRECATED
 
   /**
    *  @brief Move elements for which a predicate is true to the beginning
index 200c097f4a778e67ef4323541e973ab279ae2601..2a8c6323794825a3efd67b85f04f7725b3fbbe97 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 }
 // { dg-require-effective-target hosted }
 
index c678eb333f2d56428c628210158b9af72ba4ba71..a17429efba0346ae65075acc1e97e101cc049e26 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..4bc58a6
--- /dev/null
@@ -0,0 +1,19 @@
+// { dg-do compile }
+// { dg-add-options using-deprecated }
+// { dg-require-effective-target hosted }
+
+// 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 } 14 }
+
+  std::random_shuffle(first, last, rando);
+  // { dg-warning "deprecated" "" { target c++14 } 17 }
+}
index 2e2cadaf8629b4ad7e0e5458e4284819e5484c61..e74e6f1c866947ed92ae7da109fcf4400c8e8b24 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do run { target c++11 } }
+// { dg-options "-Wno-deprecated-declarations" }
 // { dg-add-options using-deprecated }
 // { dg-require-effective-target hosted }