]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Remove unnecessary uses of <utility>
authorJonathan Wakely <jwakely@redhat.com>
Thu, 22 Jul 2021 13:48:27 +0000 (14:48 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 27 Jul 2021 11:04:18 +0000 (12:04 +0100)
The <algorithm> header includes <utility>, with a comment referring to
UK-300, a National Body comment on the C++11 draft. That comment
proposed to move std::swap to <utility> and then require <algorithm> to
include <utility>. The comment was rejected, so we do not need to
implement the suggestion. For backwards compatibility with C++03 we do
want <algorithm> to define std::swap, but it does so anyway via
<bits/move.h>. We don't need the whole of <utility> to do that.

A few other headers that need std::swap can include <bits/move.h> to
get it, instead of <utility>.

There are several headers that include <utility> to get std::pair, but
they can use <bits/stl_pair.h> to get it without also including the
rel_ops namespace and other contents of <utility>.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

* include/std/algorithm: Do not include <utility>.
* include/std/functional: Likewise.
* include/std/regex: Include <bits/stl_pair.h> instead of
<utility>.
* include/debug/map.h: Likewise.
* include/debug/multimap.h: Likewise.
* include/debug/multiset.h: Likewise.
* include/debug/set.h: Likewise.
* include/debug/vector: Likewise.
* include/bits/fs_path.h: Likewise.
* include/bits/unique_ptr.h: Do not include <utility>.
* include/experimental/any: Likewise.
* include/experimental/executor: Likewise.
* include/experimental/memory: Likewise.
* include/experimental/optional: Likewise.
* include/experimental/socket: Use __exchange instead
of std::exchange.
* src/filesystem/ops-common.h: Likewise.
* testsuite/20_util/default_delete/48631_neg.cc: Adjust expected
errors to not use a hardcoded line number.
* testsuite/20_util/default_delete/void_neg.cc: Likewise.
* testsuite/20_util/specialized_algorithms/uninitialized_copy/constrained.cc:
Include <utility> for std::as_const.
* testsuite/20_util/specialized_algorithms/uninitialized_default_construct/constrained.cc:
Likewise.
* testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc:
Likewise.
* testsuite/20_util/specialized_algorithms/uninitialized_value_construct/constrained.cc:
Likewise.
* testsuite/23_containers/vector/cons/destructible_debug_neg.cc:
Adjust dg-error line number.

23 files changed:
libstdc++-v3/include/bits/fs_path.h
libstdc++-v3/include/bits/unique_ptr.h
libstdc++-v3/include/debug/map.h
libstdc++-v3/include/debug/multimap.h
libstdc++-v3/include/debug/multiset.h
libstdc++-v3/include/debug/set.h
libstdc++-v3/include/debug/vector
libstdc++-v3/include/experimental/any
libstdc++-v3/include/experimental/executor
libstdc++-v3/include/experimental/memory
libstdc++-v3/include/experimental/optional
libstdc++-v3/include/experimental/socket
libstdc++-v3/include/std/algorithm
libstdc++-v3/include/std/functional
libstdc++-v3/include/std/regex
libstdc++-v3/src/filesystem/ops-common.h
libstdc++-v3/testsuite/20_util/default_delete/48631_neg.cc
libstdc++-v3/testsuite/20_util/default_delete/void_neg.cc
libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/constrained.cc
libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_default_construct/constrained.cc
libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc
libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct/constrained.cc
libstdc++-v3/testsuite/23_containers/vector/cons/destructible_debug_neg.cc

index 4fcd1def92f273fff01dd9988a32705452f8dacd..3151af1e9019ead840082e79cd5a0e4308c3bd42 100644 (file)
@@ -32,7 +32,6 @@
 
 #if __cplusplus >= 201703L
 
-#include <utility>
 #include <type_traits>
 #include <locale>
 #include <iosfwd>
@@ -41,6 +40,7 @@
 #include <string_view>
 #include <system_error>
 #include <bits/stl_algobase.h>
+#include <bits/stl_pair.h>
 #include <bits/locale_conv.h>
 #include <ext/concurrence.h>
 #include <bits/shared_ptr.h>
index 0a0667a760889b7c571cfe1d6738f621e4e64949..2d8b9ed3fae6425f541eee6ad8c0e48de9eaa0fa 100644 (file)
@@ -33,7 +33,6 @@
 #include <bits/c++config.h>
 #include <debug/assertions.h>
 #include <type_traits>
-#include <utility>
 #include <tuple>
 #include <bits/stl_function.h>
 #include <bits/functional_hash.h>
index ab34b2affd9197901a6dcc467697a28e1a74b384..c0153d09abeb4c56ad73c2b47a636e8ef2a7ff8b 100644 (file)
@@ -32,7 +32,7 @@
 #include <debug/safe_sequence.h>
 #include <debug/safe_container.h>
 #include <debug/safe_iterator.h>
-#include <utility>
+#include <bits/stl_pair.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
index 96a44f4725fc11870a7b83912280eb06fb15b38e..94929344a9d343be34bf383457d1f04b13bbda27 100644 (file)
@@ -32,7 +32,7 @@
 #include <debug/safe_sequence.h>
 #include <debug/safe_container.h>
 #include <debug/safe_iterator.h>
-#include <utility>
+#include <bits/stl_pair.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
index 0e76c5ff3327353a980aea96b010741641a5cf8a..bb68d8c8f180a8abb0624f1ea37a0ae29063beca 100644 (file)
@@ -32,7 +32,7 @@
 #include <debug/safe_sequence.h>
 #include <debug/safe_container.h>
 #include <debug/safe_iterator.h>
-#include <utility>
+#include <bits/stl_pair.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
index c579de7426d2829f3eb554f45725553e1ade5a0b..cdf35ea539676591d68b44f2839c746b9e3de32e 100644 (file)
@@ -32,7 +32,7 @@
 #include <debug/safe_sequence.h>
 #include <debug/safe_container.h>
 #include <debug/safe_iterator.h>
-#include <utility>
+#include <bits/stl_pair.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
index 987bba17c2b83027bbc486e9a02f82e523c657fa..79ccf527dd627e2e5630aa1511b11a3b3fdd2702 100644 (file)
@@ -37,7 +37,6 @@ namespace std _GLIBCXX_VISIBILITY(default) { namespace __debug {
 } } // namespace std::__debug
 
 #include <vector>
-#include <utility>
 #include <debug/safe_sequence.h>
 #include <debug/safe_container.h>
 #include <debug/safe_iterator.h>
index 3bb3e8c4a0a3a1a6ed96f420708dfee251619e85..7d18f267e8b53714529675916663f0a849192e2e 100644 (file)
@@ -36,8 +36,8 @@
 
 #include <typeinfo>
 #include <new>
-#include <utility>
 #include <type_traits>
+#include <bits/move.h>
 #include <experimental/bits/lfts_config.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
index c670f2739b6cdc397f79e921408561c01734b22a..4322a7f5caf18b618be0d55fe1fd54c0ab69f7e1 100644 (file)
@@ -43,7 +43,6 @@
 #include <thread>
 #include <tuple>
 #include <unordered_map>
-#include <utility>
 #include <experimental/netfwd>
 #include <bits/unique_ptr.h>
 #include <experimental/bits/net.h>
index a74b2402f7a41c813fa354f62e0d6ba7ecf29abf..a89a5ecfa84daf15faaa7275a9b821913133e8e2 100644 (file)
@@ -40,7 +40,6 @@
 
 #include <memory>
 #include <type_traits>
-#include <utility>
 #include <experimental/bits/shared_ptr.h>
 #include <bits/functional_hash.h>
 
index ae2418f0500c7fd87e0eec9ce27d357b8c12fa6d..431d23631cf16a35886f31cbe1335ecac44fb295 100644 (file)
@@ -32,7 +32,6 @@
 
 #if __cplusplus >= 201402L
 
-#include <utility>
 #include <type_traits>
 #include <stdexcept>
 #include <new>
@@ -40,6 +39,7 @@
 #include <bits/functexcept.h>
 #include <bits/functional_hash.h>
 #include <bits/enable_special_members.h>
+#include <bits/move.h>
 #include <experimental/bits/lfts_config.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
index 9db4a245ccfc9a3ff64ceab194ce081fba871eb2..6d1c114254a753caa21f4ce31e5c524d1beb8dbe 100644 (file)
@@ -429,16 +429,16 @@ inline namespace v1
 
     __socket_impl(__socket_impl&& __rhs)
     : _M_ctx(__rhs._M_ctx),
-      _M_sockfd(std::exchange(__rhs._M_sockfd, -1)),
-      _M_bits(std::exchange(__rhs._M_bits, {}))
+      _M_sockfd(std::__exchange(__rhs._M_sockfd, -1)),
+      _M_bits(std::__exchange(__rhs._M_bits, {}))
     { }
 
     __socket_impl&
     operator=(__socket_impl&& __rhs)
     {
       _M_ctx = __rhs._M_ctx;
-      _M_sockfd = std::exchange(__rhs._M_sockfd, -1);
-      _M_bits = std::exchange(__rhs._M_bits, {});
+      _M_sockfd = std::__exchange(__rhs._M_sockfd, -1);
+      _M_bits = std::__exchange(__rhs._M_bits, {});
       return *this;
     }
 
@@ -615,7 +615,7 @@ inline namespace v1
       {
        __glibcxx_assert(is_open());
        cancel(__ec);
-       return std::exchange(_M_sockfd, -1);
+       return std::__exchange(_M_sockfd, -1);
       }
 
       template<typename _SettableSocketOption>
index 9ce4aa8423daf2366bd7de9b615fc8940b3aba56..c9df7eae1fffb38caf31d0ae3bd7dcd583182a50 100644 (file)
@@ -57,7 +57,6 @@
 
 #pragma GCC system_header
 
-#include <utility> // UK-300.
 #include <bits/stl_algobase.h>
 #include <bits/stl_algo.h>
 #if __cplusplus > 201703L
index f61f2ac8cfd803c877d05523e01898a9c4f3242b..131e6629341cb0c92c74e4c62d710e38cda474b2 100644 (file)
@@ -61,7 +61,6 @@
 # include <unordered_map>
 # include <vector>
 # include <array>
-# include <utility>
 # include <bits/stl_algo.h>
 #endif
 #if __cplusplus > 201703L
index cd33f26af0da018d397a210b8412f4f029fcc424..e623a6ed498a88f72b9090fd7289f09bb3d97c4b 100644 (file)
@@ -47,7 +47,6 @@
 #include <stack>
 #include <stdexcept>
 #include <string>
-#include <utility>
 #include <vector>
 #include <map>
 #include <cstring>
@@ -55,6 +54,7 @@
 #include <ext/aligned_buffer.h>
 #include <ext/numeric_traits.h>
 #include <bits/std_function.h>
+#include <bits/stl_pair.h>
 #include <bits/regex_constants.h>
 #include <bits/regex_error.h>
 #include <bits/regex_automaton.h>
index 529d4e09016d05aae2d01309fb6bbd3ddefe7fcf..43311e6c38fab3bc5b66b87efb0d3a43b4f403bd 100644 (file)
@@ -26,6 +26,7 @@
 #define _GLIBCXX_OPS_COMMON_H 1
 
 #include <chrono>
+#include <bits/move.h> // std::__exchange
 
 #ifdef _GLIBCXX_HAVE_UNISTD_H
 # include <unistd.h>
@@ -407,7 +408,7 @@ _GLIBCXX_BEGIN_NAMESPACE_FILESYSTEM
 
     struct CloseFD {
       ~CloseFD() { if (fd != -1) posix::close(fd); }
-      bool close() { return posix::close(std::exchange(fd, -1)) == 0; }
+      bool close() { return posix::close(std::__exchange(fd, -1)) == 0; }
       int fd;
     };
 
index 5de981665d9ed1c683d6e07f1962099692cd37bc..3e80b73603ef7b3729931fb3b42d2cbc41851761 100644 (file)
@@ -26,4 +26,4 @@ struct D : B { };
 D d;
 std::default_delete<B[]> db;
 typedef decltype(db(&d)) type; // { dg-error "no match" }
-// { dg-error "no type" "" { target *-*-* } 116 }
+// { dg-prune-output "no type named 'type' in 'struct std::enable_if" }
index 217c39b5eb47fabeb83c90569c08d589d6b6a85b..ac4eabc53412cfebae3bcbf1dd366dacfb2e452a 100644 (file)
@@ -25,5 +25,5 @@ void test01()
 {
   std::default_delete<void> d;
   d(nullptr);   // { dg-error "here" }
-  // { dg-error "incomplete" "" { target *-*-* } 81 }
+  // { dg-error "delete pointer to incomplete type" "" { target *-*-* } 0 }
 }
index ac9128e6a00ea78e269a10d6a21dd76aa17e83e6..7946effcf3af3eaf60cc339172c63de450e492a2 100644 (file)
@@ -25,6 +25,7 @@
 #include <span>
 #include <string>
 #include <vector>
+#include <utility>
 
 #include <testsuite_hooks.h>
 #include <testsuite_iterators.h>
index 05824c021a83b3ca2c5e8bae6935747bad030e2e..7267738a4af0802e04cb6f4dd76082d2ef06b143 100644 (file)
@@ -25,6 +25,7 @@
 #include <span>
 #include <string>
 #include <vector>
+#include <utility>
 
 #include <testsuite_hooks.h>
 #include <testsuite_iterators.h>
index cc8cf0beef86ac1d538bd68f9d90cad220d53a97..8759d042bb60fa0607f111567bff99dc6815e43a 100644 (file)
@@ -25,6 +25,7 @@
 #include <span>
 #include <string>
 #include <vector>
+#include <utility>
 
 #include <testsuite_hooks.h>
 #include <testsuite_iterators.h>
index efcf138dd5fa1ed901a3e9471e75640d1da0792c..164d9ca667b30adfd4b3addd0202f6c3f76424d0 100644 (file)
@@ -25,6 +25,7 @@
 #include <span>
 #include <string>
 #include <vector>
+#include <utility>
 
 #include <testsuite_hooks.h>
 #include <testsuite_iterators.h>
index 2283d99b2601b44fafd8e0b793725a5f8956cc81..b85199e693fd3e5984947db3231d9f8218af53d2 100644 (file)
@@ -46,7 +46,7 @@ test02()
 // { dg-error "value type is destructible" "" { target *-*-* } 0 }
 
 // In Debug Mode the "required from here" errors come from <debug/vector>
-// { dg-error "required from here" "" { target *-*-* } 173 }
+// { dg-error "required from here" "" { target *-*-* } 172 }
 
 // Needed because of PR c++/92193
 // { dg-prune-output "deleted function" }