From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 1DD353858D35; Wed, 26 Jul 2023 16:02:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1DD353858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690387373; bh=csrXlFy+1kVayCjqNgJZCNngYNrFytFEfykwqzNiz5A=; h=From:To:Subject:Date:From; b=lhYBFizQAHKS3GQHyve7a8+QeqcMoyoJU6KIm31xMN45WBF3RgAPTKYZM+cPEBMkp LVuMqXxq/g37Ljr5HcohKnlG48IfFyEB2wVKedjC/9lEra9/XxuQBtjLuApm+NjL80 A9TdV4HguoqoYpp7/K/DIKXklXfoj7R8fMat+EjQ= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-2796] libstdc++: Add deprecated attribute to std::random_shuffle declarations X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: d74aed3d7aefbb661ae629a91ca7baa4916085f0 X-Git-Newrev: c01b344e814001e07fd304ce98d013d811e90192 Message-Id: <20230726160253.1DD353858D35@sourceware.org> Date: Wed, 26 Jul 2023 16:02:53 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c01b344e814001e07fd304ce98d013d811e90192 commit r14-2796-gc01b344e814001e07fd304ce98d013d811e90192 Author: Jonathan Wakely Date: Wed Jul 26 14:05:58 2023 +0100 libstdc++: Add deprecated attribute to std::random_shuffle declarations We already have these attributes on the definitions in but they don't work due to PR c++/84542. Add the attributes to the declarations in 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. Diff: --- libstdc++-v3/include/bits/algorithmfwd.h | 2 ++ libstdc++-v3/include/bits/stl_algo.h | 6 +++--- .../testsuite/25_algorithms/random_shuffle/1.cc | 1 + .../testsuite/25_algorithms/random_shuffle/59603.cc | 1 + .../25_algorithms/random_shuffle/deprecated.cc | 19 +++++++++++++++++++ .../25_algorithms/random_shuffle/moveable.cc | 1 + 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/bits/algorithmfwd.h b/libstdc++-v3/include/bits/algorithmfwd.h index 0d623901cd2..130943d2340 100644 --- a/libstdc++-v3/include/bits/algorithmfwd.h +++ b/libstdc++-v3/include/bits/algorithmfwd.h @@ -832,10 +832,12 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO #if _GLIBCXX_HOSTED template + _GLIBCXX14_DEPRECATED_SUGGEST("std::shuffle") void random_shuffle(_RAIter, _RAIter); template + _GLIBCXX14_DEPRECATED_SUGGEST("std::shuffle") void random_shuffle(_RAIter, _RAIter, #if __cplusplus >= 201103L diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 2c52ed51402..3abf0f69d46 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -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 @@ -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 @@ -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 diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/1.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/1.cc index 200c097f4a7..2a8c6323794 100644 --- a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/1.cc +++ b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/1.cc @@ -15,6 +15,7 @@ // with this library; see the file COPYING3. If not see // . +// { dg-options "-Wno-deprecated-declarations" } // { dg-add-options using-deprecated } // { dg-require-effective-target hosted } diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/59603.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/59603.cc index c678eb333f2..a17429efba0 100644 --- a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/59603.cc +++ b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/59603.cc @@ -16,6 +16,7 @@ // . // { 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 index 00000000000..4bc58a6447e --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/deprecated.cc @@ -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 + +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 } +} diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc index 2e2cadaf862..e74e6f1c866 100644 --- a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc +++ b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc @@ -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 }