@@ -478,6 +478,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
noexcept(noexcept(__x.swap(__y)))
{ __x.swap(__y); }
+
+#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
+ template<typename _T1, typename _T2>
+ inline
+ typename enable_if<__not_<__and_<__is_swappable<_T1>,
+ __is_swappable<_T2>>>::value>::type
+ swap(pair<_T1, _T2>&, pair<_T1, _T2>&) = delete;
+#endif
#endif // __cplusplus >= 201103L
/**
@@ -649,6 +649,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
swap(unique_ptr<_Tp, _Dp>& __x,
unique_ptr<_Tp, _Dp>& __y) noexcept
{ __x.swap(__y); }
+#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
+ template<typename _Tp, typename _Dp>
+ inline
+ typename enable_if<__not_<__is_swappable<_Dp>>::value>::type
+ swap(unique_ptr<_Tp, _Dp>&,
+ unique_ptr<_Tp, _Dp>&) = delete;
+#endif
template<typename _Tp, typename _Dp,
typename _Up, typename _Ep>
@@ -287,6 +287,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
noexcept(noexcept(__one.swap(__two)))
{ __one.swap(__two); }
+#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
+ template<typename _Tp, std::size_t _Nm>
+ inline
+ typename enable_if<__not_<
+ typename _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::_Is_swappable>
+ ::value>::type
+ swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&) = delete;
+#endif
template<std::size_t _Int, typename _Tp, std::size_t _Nm>
constexpr _Tp&
@@ -930,6 +930,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ __lhs.swap(__rhs); }
template<typename _Tp>
+ inline enable_if_t<!(is_move_constructible_v<_Tp> && is_swappable_v<_Tp>)>
+ swap(optional<_Tp>&, optional<_Tp>&) = delete;
+
+ template<typename _Tp>
constexpr optional<decay_t<_Tp>>
make_optional(_Tp&& __t)
{ return optional<decay_t<_Tp>> { std::forward<_Tp>(__t) }; }
@@ -877,10 +877,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return false; }
template<typename... _Types>
- inline auto swap(variant<_Types...>& __lhs, variant<_Types...>& __rhs)
- noexcept(noexcept(__lhs.swap(__rhs))) -> decltype(__lhs.swap(__rhs))
+ inline enable_if_t<__and_<is_move_constructible<_Types>...,
+ is_swappable<_Types>...>::value>
+ swap(variant<_Types...>& __lhs, variant<_Types...>& __rhs)
+ noexcept(noexcept(__lhs.swap(__rhs)))
{ __lhs.swap(__rhs); }
+ template<typename... _Types>
+ inline enable_if_t<__not_<__and_<is_move_constructible<_Types>...,
+ is_swappable<_Types>...>>::value>
+ swap(variant<_Types...>&, variant<_Types...>&) = delete;
+
class bad_variant_access : public exception
{
public:
@@ -33,11 +33,11 @@ void swap(B&, B&) noexcept(false);
static_assert( std::is_swappable_v<std::optional<B>> );
static_assert( !std::is_nothrow_swappable_v<std::optional<B>> );
-// Not swappable, but optional<C> is swappable via the generic std::swap.
+// Not swappable, and optional<C> not swappable via the generic std::swap.
struct C { };
void swap(C&, C&) = delete;
-static_assert( std::is_swappable_v<std::optional<C>> );
+static_assert( !std::is_swappable_v<std::optional<C>> );
// Not swappable, and optional<D> not swappable via the generic std::swap.
struct D { D(D&&) = delete; };
new file mode 100644
@@ -0,0 +1,35 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <utility>
+
+// Not swappable, and pair not swappable via the generic std::swap.
+struct C { };
+void swap(C&, C&) = delete;
+
+static_assert( !std::is_swappable_v<std::pair<int, C>> );
+static_assert( !std::is_swappable_v<std::pair<C, int>> );
+
+// Not swappable, and pair not swappable via the generic std::swap.
+struct D { D(D&&) = delete; };
+
+static_assert( !std::is_swappable_v<std::pair<int, D>> );
+static_assert( !std::is_swappable_v<std::pair<D, int>> );
new file mode 100644
@@ -0,0 +1,33 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <memory>
+
+// Not swappable, and unique_ptr not swappable via the generic std::swap.
+struct C { };
+void swap(C&, C&) = delete;
+
+static_assert( !std::is_swappable_v<std::unique_ptr<int, C>> );
+
+// Not swappable, and unique_ptr not swappable via the generic std::swap.
+struct D { D(D&&) = delete; };
+
+static_assert( !std::is_swappable_v<std::unique_ptr<int, D>> );
+
@@ -219,6 +219,21 @@ void test_relational()
}
}
+// Not swappable, and variant<C> not swappable via the generic std::swap.
+struct C { };
+void swap(C&, C&) = delete;
+
+static_assert( !std::is_swappable_v<variant<C>> );
+static_assert( !std::is_swappable_v<variant<int, C>> );
+static_assert( !std::is_swappable_v<variant<C, int>> );
+
+// Not swappable, and variant<D> not swappable via the generic std::swap.
+struct D { D(D&&) = delete; };
+
+static_assert( !std::is_swappable_v<variant<D>> );
+static_assert( !std::is_swappable_v<variant<int, D>> );
+static_assert( !std::is_swappable_v<variant<D, int>> );
+
void test_swap()
{
variant<int, string> a, b;
new file mode 100644
@@ -0,0 +1,33 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <array>
+
+// Not swappable, and pair not swappable via the generic std::swap.
+struct C { };
+void swap(C&, C&) = delete;
+
+static_assert( !std::is_swappable_v<std::array<C, 42>> );
+
+// Not swappable, and pair not swappable via the generic std::swap.
+struct D { D(D&&) = delete; };
+
+static_assert( !std::is_swappable_v<std::array<D, 42>> );
+
@@ -27,6 +27,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 *-*-* } 295 }
-// { dg-error "static assertion failed" "" { target *-*-* } 304 }
+// { dg-error "static assertion failed" "" { target *-*-* } 303 }
// { dg-error "static assertion failed" "" { target *-*-* } 312 }
+// { dg-error "static assertion failed" "" { target *-*-* } 320 }
@@ -22,4 +22,4 @@
typedef std::tuple_element<1, std::array<int, 1>>::type type;
-// { dg-error "static assertion failed" "" { target *-*-* } 343 }
+// { dg-error "static assertion failed" "" { target *-*-* } 351 }