From: Jonathan Wakely Date: Mon, 2 Aug 2021 17:35:42 +0000 (+0100) Subject: libstdc++: Deprecate std::random_shuffle for C++14 X-Git-Tag: basepoints/gcc-13~5613 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f2f4b87910506effb8dffffc60eeb2451573126;p=thirdparty%2Fgcc.git libstdc++: Deprecate std::random_shuffle for C++14 The std::random_shuffle algorithm was removed in C++14 (without deprecation). This adds the deprecated attribute for C++14 and later, so that users are warned they should not be using it in those dialects. Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: * doc/xml/manual/evolution.xml: Document deprecation. * doc/html/*: Regenerate. * include/bits/c++config (_GLIBCXX14_DEPRECATED): Define. (_GLIBCXX14_DEPRECATED_SUGGEST): Define. * include/bits/stl_algo.h (random_shuffle): Deprecate for C++14 and later. * testsuite/25_algorithms/headers/algorithm/synopsis.cc: Adjust for C++11 and C++14 changes to std::random_shuffle and std::shuffle. * testsuite/25_algorithms/random_shuffle/1.cc: Add options to use deprecated algorithms. * testsuite/25_algorithms/random_shuffle/59603.cc: Likewise. * testsuite/25_algorithms/random_shuffle/moveable.cc: Likewise. * testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/2.cc: Likewise. * testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/pod.cc: Likewise. --- diff --git a/libstdc++-v3/doc/html/index.html b/libstdc++-v3/doc/html/index.html index ed1a05f36f78..d21efe58a58d 100644 --- a/libstdc++-v3/doc/html/index.html +++ b/libstdc++-v3/doc/html/index.html @@ -142,7 +142,7 @@ Existing tests
C++11 Requirements Test Sequence Descriptions -
ABI Policy and Guidelines
The C++ Interface
Versioning
Goals
History
Prerequisites
Configuring
Checking Active
Allowed Changes
Prohibited Changes
Implementation
Testing
Single ABI Testing
Multiple ABI Testing
Outstanding Issues
API Evolution and Deprecation History
3.0
3.1
3.2
3.3
3.4
4.0
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
5
5.3
6
7
7.2
7.3
8
9
10
11
Backwards Compatibility
First
Second
Third
Pre-ISO headers removed
Extension headers hash_map, hash_set moved to ext or backwards
No ios::nocreate/ios::noreplace. +
ABI Policy and Guidelines
The C++ Interface
Versioning
Goals
History
Prerequisites
Configuring
Checking Active
Allowed Changes
Prohibited Changes
Implementation
Testing
Single ABI Testing
Multiple ABI Testing
Outstanding Issues
API Evolution and Deprecation History
3.0
3.1
3.2
3.3
3.4
4.0
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
5
5.3
6
7
7.2
7.3
8
9
10
11
12
Backwards Compatibility
First
Second
Third
Pre-ISO headers removed
Extension headers hash_map, hash_set moved to ext or backwards
No ios::nocreate/ios::noreplace.
No stream::attach(int fd)
diff --git a/libstdc++-v3/doc/html/manual/api.html b/libstdc++-v3/doc/html/manual/api.html index 70889a583f90..376a4035fa67 100644 --- a/libstdc++-v3/doc/html/manual/api.html +++ b/libstdc++-v3/doc/html/manual/api.html @@ -436,4 +436,8 @@ now defaults to zero. Calling reserve() with no arguments is equivalent to shrink_to_fit(), but is deprecated. shrink_to_fit() should be used instead. +

12

+The std::random_shuffle algorithms are deprecated +for C++14 and later. The C++11 std::shuffle algorithm +can be used instead.

\ No newline at end of file diff --git a/libstdc++-v3/doc/html/manual/appendix.html b/libstdc++-v3/doc/html/manual/appendix.html index 5ed69411eaba..bd462e9dddd3 100644 --- a/libstdc++-v3/doc/html/manual/appendix.html +++ b/libstdc++-v3/doc/html/manual/appendix.html @@ -16,7 +16,7 @@ Existing tests
C++11 Requirements Test Sequence Descriptions -
ABI Policy and Guidelines
The C++ Interface
Versioning
Goals
History
Prerequisites
Configuring
Checking Active
Allowed Changes
Prohibited Changes
Implementation
Testing
Single ABI Testing
Multiple ABI Testing
Outstanding Issues
API Evolution and Deprecation History
3.0
3.1
3.2
3.3
3.4
4.0
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
5
5.3
6
7
7.2
7.3
8
9
10
11
Backwards Compatibility
First
Second
Third
Pre-ISO headers removed
Extension headers hash_map, hash_set moved to ext or backwards
No ios::nocreate/ios::noreplace. +
ABI Policy and Guidelines
The C++ Interface
Versioning
Goals
History
Prerequisites
Configuring
Checking Active
Allowed Changes
Prohibited Changes
Implementation
Testing
Single ABI Testing
Multiple ABI Testing
Outstanding Issues
API Evolution and Deprecation History
3.0
3.1
3.2
3.3
3.4
4.0
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
5
5.3
6
7
7.2
7.3
8
9
10
11
12
Backwards Compatibility
First
Second
Third
Pre-ISO headers removed
Extension headers hash_map, hash_set moved to ext or backwards
No ios::nocreate/ios::noreplace.
No stream::attach(int fd)
diff --git a/libstdc++-v3/doc/html/manual/appendix_porting.html b/libstdc++-v3/doc/html/manual/appendix_porting.html index bfecf52a11da..3d7fb564f4b8 100644 --- a/libstdc++-v3/doc/html/manual/appendix_porting.html +++ b/libstdc++-v3/doc/html/manual/appendix_porting.html @@ -14,7 +14,7 @@ Existing tests
C++11 Requirements Test Sequence Descriptions -
ABI Policy and Guidelines
The C++ Interface
Versioning
Goals
History
Prerequisites
Configuring
Checking Active
Allowed Changes
Prohibited Changes
Implementation
Testing
Single ABI Testing
Multiple ABI Testing
Outstanding Issues
API Evolution and Deprecation History
3.0
3.1
3.2
3.3
3.4
4.0
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
5
5.3
6
7
7.2
7.3
8
9
10
11
Backwards Compatibility
First
Second
Third
Pre-ISO headers removed
Extension headers hash_map, hash_set moved to ext or backwards
No ios::nocreate/ios::noreplace. +
ABI Policy and Guidelines
The C++ Interface
Versioning
Goals
History
Prerequisites
Configuring
Checking Active
Allowed Changes
Prohibited Changes
Implementation
Testing
Single ABI Testing
Multiple ABI Testing
Outstanding Issues
API Evolution and Deprecation History
3.0
3.1
3.2
3.3
3.4
4.0
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
5
5.3
6
7
7.2
7.3
8
9
10
11
12
Backwards Compatibility
First
Second
Third
Pre-ISO headers removed
Extension headers hash_map, hash_set moved to ext or backwards
No ios::nocreate/ios::noreplace.
No stream::attach(int fd)
diff --git a/libstdc++-v3/doc/html/manual/index.html b/libstdc++-v3/doc/html/manual/index.html index e34210ee5d98..380cedf52978 100644 --- a/libstdc++-v3/doc/html/manual/index.html +++ b/libstdc++-v3/doc/html/manual/index.html @@ -123,7 +123,7 @@ Existing tests
C++11 Requirements Test Sequence Descriptions -
ABI Policy and Guidelines
The C++ Interface
Versioning
Goals
History
Prerequisites
Configuring
Checking Active
Allowed Changes
Prohibited Changes
Implementation
Testing
Single ABI Testing
Multiple ABI Testing
Outstanding Issues
API Evolution and Deprecation History
3.0
3.1
3.2
3.3
3.4
4.0
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
5
5.3
6
7
7.2
7.3
8
9
10
11
Backwards Compatibility
First
Second
Third
Pre-ISO headers removed
Extension headers hash_map, hash_set moved to ext or backwards
No ios::nocreate/ios::noreplace. +
ABI Policy and Guidelines
The C++ Interface
Versioning
Goals
History
Prerequisites
Configuring
Checking Active
Allowed Changes
Prohibited Changes
Implementation
Testing
Single ABI Testing
Multiple ABI Testing
Outstanding Issues
API Evolution and Deprecation History
3.0
3.1
3.2
3.3
3.4
4.0
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
5
5.3
6
7
7.2
7.3
8
9
10
11
12
Backwards Compatibility
First
Second
Third
Pre-ISO headers removed
Extension headers hash_map, hash_set moved to ext or backwards
No ios::nocreate/ios::noreplace.
No stream::attach(int fd)
diff --git a/libstdc++-v3/doc/xml/manual/evolution.xml b/libstdc++-v3/doc/xml/manual/evolution.xml index 55b8903baff5..59b71b04442b 100644 --- a/libstdc++-v3/doc/xml/manual/evolution.xml +++ b/libstdc++-v3/doc/xml/manual/evolution.xml @@ -1019,4 +1019,14 @@ now defaults to zero. +
<constant>12</constant> + + +The std::random_shuffle algorithms are deprecated +for C++14 and later. The C++11 std::shuffle algorithm +can be used instead. + + +
+ diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config index 69ace386dd7a..32b8957f8140 100644 --- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -80,6 +80,8 @@ // _GLIBCXX_DEPRECATED_SUGGEST( string-literal ) // _GLIBCXX11_DEPRECATED // _GLIBCXX11_DEPRECATED_SUGGEST( string-literal ) +// _GLIBCXX14_DEPRECATED +// _GLIBCXX14_DEPRECATED_SUGGEST( string-literal ) // _GLIBCXX17_DEPRECATED // _GLIBCXX17_DEPRECATED_SUGGEST( string-literal ) // _GLIBCXX20_DEPRECATED( string-literal ) @@ -105,6 +107,14 @@ # define _GLIBCXX11_DEPRECATED_SUGGEST(ALT) #endif +#if defined(__DEPRECATED) && (__cplusplus >= 201403L) +# define _GLIBCXX14_DEPRECATED _GLIBCXX_DEPRECATED +# define _GLIBCXX14_DEPRECATED_SUGGEST(ALT) _GLIBCXX_DEPRECATED_SUGGEST(ALT) +#else +# define _GLIBCXX14_DEPRECATED +# define _GLIBCXX14_DEPRECATED_SUGGEST(ALT) +#endif + #if defined(__DEPRECATED) && (__cplusplus >= 201703L) # define _GLIBCXX17_DEPRECATED [[__deprecated__]] # define _GLIBCXX17_DEPRECATED_SUGGEST(ALT) _GLIBCXX_DEPRECATED_SUGGEST(ALT) diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index a18bb000d0c1..54ad383711f0 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -56,7 +56,6 @@ #ifndef _STL_ALGO_H #define _STL_ALGO_H 1 -#include // for rand #include #include #include // for _Temporary_buffer @@ -66,6 +65,10 @@ #include #endif +#if _GLIBCXX_HOSTED && (__cplusplus <= 201103L || _GLIBCXX_USE_DEPRECATED) +#include // for rand +#endif + // See concept_check.h for the __glibcxx_*_requires macros. namespace std _GLIBCXX_VISIBILITY(default) @@ -4551,6 +4554,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO std::__iterator_category(__result)); } +#if __cplusplus <= 201103L || _GLIBCXX_USE_DEPRECATED #if _GLIBCXX_HOSTED /** * @brief Randomly shuffle the elements of a sequence. @@ -4564,6 +4568,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * equally likely. */ template + _GLIBCXX14_DEPRECATED_SUGGEST("std::shuffle") inline void random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) { @@ -4599,6 +4604,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * range [0,N). */ template + _GLIBCXX14_DEPRECATED_SUGGEST("std::shuffle") void random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, #if __cplusplus >= 201103L @@ -4621,7 +4627,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO std::iter_swap(__i, __j); } } - +#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/headers/algorithm/synopsis.cc b/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc index d1540e26db47..dbf58fb64a64 100644 --- a/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc +++ b/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc @@ -318,6 +318,7 @@ namespace std _OIter rotate_copy (_FIter, _FIter, _FIter, _OIter); +#if __cplusplus <= 201103L template void random_shuffle(_RAIter, _RAIter); @@ -325,6 +326,13 @@ namespace std template void random_shuffle(_RAIter, _RAIter, _Generator&); +#endif + +#if __cplusplus >= 201103L + template + void + shuffle(_RAIter, _RAIter, _UniformRandomBitGenerator&); +#endif // 25.2.12, partitions: template diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/1.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/1.cc index e9cdf5ebc333..bf4eda792dde 100644 --- a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/1.cc +++ b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/1.cc @@ -15,6 +15,8 @@ // with this library; see the file COPYING3. If not see // . +// { dg-add-options using-deprecated } + // 25.2.11 random_shuffle() #include diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/59603.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/59603.cc index 50370c70f54f..3d2d6b2b05b4 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-add-options using-deprecated } // { dg-require-debug-mode "" } // libstdc++/59603 diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc index b2747bdb191a..4d15c280f5b6 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-add-options using-deprecated } // Copyright (C) 2009-2021 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/2.cc index 4761f01f704b..206c237cbc6c 100644 --- a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/2.cc +++ b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/2.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-add-options using-deprecated } // 2007-09-20 Benjamin Kosnik diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/pod.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/pod.cc index 4536a3f9210d..5e69aa60420a 100644 --- a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/pod.cc +++ b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/pod.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-add-options using-deprecated } // 2007-09-20 Benjamin Kosnik