]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add comments to deleted std::swap overloads for LWG 2766
authorJonathan Wakely <jwakely@redhat.com>
Sun, 13 Jul 2025 14:34:15 +0000 (15:34 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 14 Jul 2025 20:41:37 +0000 (21:41 +0100)
We pre-emptively implemented part of LWG 2766, which still hasn't been
approved. Add comments to the deleted swap overloads saying why they're
there, because the standard doesn't require them.

libstdc++-v3/ChangeLog:

* include/bits/stl_pair.h (swap): Add comment to deleted
overload.
* include/bits/unique_ptr.h (swap): Likewise.
* include/std/array (swap): Likewise.
* include/std/optional (swap): Likewise.
* include/std/tuple (swap): Likewise.
* include/std/variant (swap): Likewise.
* testsuite/23_containers/array/tuple_interface/get_neg.cc:
Adjust dg-error line numbers.

libstdc++-v3/include/bits/stl_pair.h
libstdc++-v3/include/bits/unique_ptr.h
libstdc++-v3/include/std/array
libstdc++-v3/include/std/optional
libstdc++-v3/include/std/tuple
libstdc++-v3/include/std/variant
libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc

index 8c57712b46177cc554e8fe0dd4f99d1b3a1ce3af..393f6a0161962ae9086bb818ff0ac6118a7bd2c7 100644 (file)
@@ -1132,6 +1132,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif // C++23
 
 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 2766. Swapping non-swappable types
   template<typename _T1, typename _T2>
     typename enable_if<!__and_<__is_swappable<_T1>,
                               __is_swappable<_T2>>::value>::type
index 6ae46a93800c1ecad448872b2a6faa0dafbd082f..d76ad63ba7bfbbd2b5c3d3b400b5e732dbad008b 100644 (file)
@@ -832,6 +832,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     { __x.swap(__y); }
 
 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 2766. Swapping non-swappable types
   template<typename _Tp, typename _Dp>
     typename enable_if<!__is_swappable<_Dp>::value>::type
     swap(unique_ptr<_Tp, _Dp>&,
index fdcf0b073762484a233e4b50055b353e5ec5757f..12f010921db14073dc6a414de43ad94e28e968d2 100644 (file)
@@ -381,6 +381,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     { __one.swap(__two); }
 
 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 2766. Swapping non-swappable types
   template<typename _Tp, std::size_t _Nm>
     __enable_if_t<!__array_traits<_Tp, _Nm>::_Is_swappable::value>
     swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&) = delete;
index cc7af5bbd7d2c331227182f5560b5d110472e25f..e5051d72c8288d282fa2cd179b7b58674bd91190 100644 (file)
@@ -1740,6 +1740,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     noexcept(noexcept(__lhs.swap(__rhs)))
     { __lhs.swap(__rhs); }
 
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 2766. Swapping non-swappable types
   template<typename _Tp>
     enable_if_t<!(is_move_constructible_v<_Tp> && is_swappable_v<_Tp>)>
     swap(optional<_Tp>&, optional<_Tp>&) = delete;
index b39ce710984ce9eed17c9f8029f569a37684cca7..2e6499eab22ded97997003aa46c657ffabcacf92 100644 (file)
@@ -2835,6 +2835,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     { __x.swap(__y); }
 
 #if __cpp_lib_ranges_zip // >= C++23
+  /// Exchange the values of two const tuples (if const elements can be swapped)
   template<typename... _Elements>
     requires (is_swappable_v<const _Elements> && ...)
     constexpr void
@@ -2844,7 +2845,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif // C++23
 
 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
-  /// Exchange the values of two const tuples (if const elements can be swapped)
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 2766. Swapping non-swappable types
   template<typename... _Elements>
     _GLIBCXX20_CONSTEXPR
     typename enable_if<!__and_<__is_swappable<_Elements>...>::value>::type
index ec46ff1dabb51076b4befcce15adbfa52c7220cf..2f44f9700283d866905ae8e0e6a5ecb2dba1a135 100644 (file)
@@ -1387,6 +1387,8 @@ namespace __detail::__variant
     noexcept(noexcept(__lhs.swap(__rhs)))
     { __lhs.swap(__rhs); }
 
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 2766. Swapping non-swappable types
   template<typename... _Types>
     enable_if_t<!((is_move_constructible_v<_Types> && ...)
                   && (is_swappable_v<_Types> && ...))>
index 25511e79941d19222f7b26feaa94d82a0b1205be..e1e9ce9bdac14132f763fa87d16613306efe47e6 100644 (file)
@@ -26,6 +26,6 @@ int n1 = std::get<1>(a);
 int n2 = std::get<1>(std::move(a));
 int n3 = std::get<1>(ca);
 
-// { dg-error "static assertion failed" "" { target *-*-* } 394 }
-// { dg-error "static assertion failed" "" { target *-*-* } 403 }
-// { dg-error "static assertion failed" "" { target *-*-* } 412 }
+// { dg-error "static assertion failed" "" { target *-*-* } 396 }
+// { dg-error "static assertion failed" "" { target *-*-* } 405 }
+// { dg-error "static assertion failed" "" { target *-*-* } 414 }