]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix [multi]map/[multi]set move constructors noexcept qualification
authorFrançois Dumont <fdumont@gcc.gnu.org>
Fri, 3 Jul 2020 06:13:19 +0000 (08:13 +0200)
committerFrançois Dumont <fdumont@gcc.gnu.org>
Wed, 8 Jul 2020 06:02:16 +0000 (08:02 +0200)
Container move constructors shall not consider their allocator move
constructor qualification.

libstdc++-v3/ChangeLog:

* include/bits/stl_tree.h (_Rb_tree_impl(_Rb_tree_impl&&)): Add noexcept
qualification based only on _Compare one.
* testsuite/23_containers/map/cons/noexcept_move_construct.cc: Add
static asserts.
* testsuite/23_containers/multimap/cons/noexcept_move_construct.cc:
Likewise.
* testsuite/23_containers/multiset/cons/noexcept_move_construct.cc:
Likewise.
* testsuite/23_containers/set/cons/noexcept_move_construct.cc: Likewise.

libstdc++-v3/include/bits/stl_tree.h
libstdc++-v3/testsuite/23_containers/map/cons/noexcept_move_construct.cc
libstdc++-v3/testsuite/23_containers/multimap/cons/noexcept_move_construct.cc
libstdc++-v3/testsuite/23_containers/multiset/cons/noexcept_move_construct.cc
libstdc++-v3/testsuite/23_containers/set/cons/noexcept_move_construct.cc

index 5be15afa25754f8a7a2c405c55328a08bbf1be34..21b72cebf2e078ae893c61917ff1094b81bfeefd 100644 (file)
@@ -698,7 +698,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          : _Node_allocator(__a), _Base_key_compare(__comp)
          { }
 #else
-         _Rb_tree_impl(_Rb_tree_impl&&) = default;
+         _Rb_tree_impl(_Rb_tree_impl&&)
+           noexcept( is_nothrow_move_constructible<_Base_key_compare>::value )
+         = default;
 
          explicit
          _Rb_tree_impl(_Node_allocator&& __a)
index 119b199ddffaf9da69c6283a404fa1a3b09412dc..25d1c9b5aca37f54015b2f14e383d6b370d0b6c8 100644 (file)
@@ -29,6 +29,33 @@ static_assert( std::is_nothrow_constructible<mtype,
               mtype&&, const typename mtype::allocator_type&>::value,
               "noexcept move constructor with allocator" );
 
+template<typename Type>
+  class not_noexcept_move_constructor_alloc : public std::allocator<Type>
+  {
+  public:
+    not_noexcept_move_constructor_alloc() noexcept { }
+
+    not_noexcept_move_constructor_alloc(
+       const not_noexcept_move_constructor_alloc& x) noexcept
+    : std::allocator<Type>(x)
+    { }
+
+    not_noexcept_move_constructor_alloc(
+       not_noexcept_move_constructor_alloc&& x) noexcept(false)
+    : std::allocator<Type>(std::move(x))
+    { }
+
+    template<typename _Tp1>
+      struct rebind
+      { typedef not_noexcept_move_constructor_alloc<_Tp1> other; };
+  };
+
+typedef std::map<int, int, std::less<int>,
+                not_noexcept_move_constructor_alloc<std::pair<const int, int>>> amtype;
+
+static_assert( std::is_nothrow_move_constructible<amtype>::value,
+              "noexcept move constructor with not noexcept alloc" );
+
 struct not_noexcept_less
 {
   not_noexcept_less() = default;
@@ -42,6 +69,9 @@ struct not_noexcept_less
 
 typedef std::map<int, int, not_noexcept_less> emtype;
 
+static_assert( !std::is_nothrow_move_constructible<emtype>::value,
+              "not noexcept move constructor with not noexcept less" );
+
 static_assert( !std::is_nothrow_constructible<emtype, emtype&&,
               const typename emtype::allocator_type&>::value,
-              "except move constructor with allocator" );
+              "not noexcept move constructor with allocator" );
index 44c3015a282de914156b1e1cee845d00846a0094..af545ae297c07545a6214545392ea16fec215608 100644 (file)
@@ -29,6 +29,33 @@ static_assert( std::is_nothrow_constructible<mmtype,
               mmtype&&, const typename mmtype::allocator_type&>::value,
               "noexcept move constructor with allocator" );
 
+template<typename Type>
+  class not_noexcept_move_constructor_alloc : public std::allocator<Type>
+  {
+  public:
+    not_noexcept_move_constructor_alloc() noexcept { }
+
+    not_noexcept_move_constructor_alloc(
+       const not_noexcept_move_constructor_alloc& x) noexcept
+    : std::allocator<Type>(x)
+    { }
+
+    not_noexcept_move_constructor_alloc(
+       not_noexcept_move_constructor_alloc&& x) noexcept(false)
+    : std::allocator<Type>(std::move(x))
+    { }
+
+    template<typename _Tp1>
+      struct rebind
+      { typedef not_noexcept_move_constructor_alloc<_Tp1> other; };
+  };
+
+typedef std::multimap<int, int, std::less<int>,
+                     not_noexcept_move_constructor_alloc<std::pair<const int, int>>> ammtype;
+
+static_assert( std::is_nothrow_move_constructible<ammtype>::value,
+              "noexcept move constructor with not noexcept alloc" );
+
 struct not_noexcept_less
 {
   not_noexcept_less() = default;
@@ -42,6 +69,9 @@ struct not_noexcept_less
 
 typedef std::multimap<int, int, not_noexcept_less> emmtype;
 
+static_assert( !std::is_nothrow_move_constructible<emmtype>::value,
+              "not noexcept move constructor with not noexcept less" );
+
 static_assert( !std::is_nothrow_constructible<emmtype, emmtype&&,
               const typename emmtype::allocator_type&>::value,
-              "except move constructor with allocator" );
+              "not noexcept move constructor with allocator" );
index 225b2206ad4456094cb65a8ffe4fa1a41d088572..ed4d9128606da7a6fdb2bfd8004d5b81e88554aa 100644 (file)
@@ -29,6 +29,33 @@ static_assert( std::is_nothrow_constructible<mstype,
               mstype&&, const typename mstype::allocator_type&>::value,
               "noexcept move constructor with allocator" );
 
+template<typename Type>
+  class not_noexcept_move_constructor_alloc : public std::allocator<Type>
+  {
+  public:
+    not_noexcept_move_constructor_alloc() noexcept { }
+
+    not_noexcept_move_constructor_alloc(
+       const not_noexcept_move_constructor_alloc& x) noexcept
+    : std::allocator<Type>(x)
+    { }
+
+    not_noexcept_move_constructor_alloc(
+       not_noexcept_move_constructor_alloc&& x) noexcept(false)
+    : std::allocator<Type>(std::move(x))
+    { }
+
+    template<typename _Tp1>
+      struct rebind
+      { typedef not_noexcept_move_constructor_alloc<_Tp1> other; };
+  };
+
+typedef std::multiset<int, std::less<int>,
+                not_noexcept_move_constructor_alloc<int>> amstype;
+
+static_assert( std::is_nothrow_move_constructible<amstype>::value,
+              "noexcept move constructor with not noexcept alloc" );
+
 struct not_noexcept_less
 {
   not_noexcept_less() = default;
@@ -42,6 +69,9 @@ struct not_noexcept_less
 
 typedef std::multiset<int, not_noexcept_less> emstype;
 
+static_assert( !std::is_nothrow_move_constructible<emstype>::value,
+              "not noexcept move constructor with not noexcept less" );
+
 static_assert( !std::is_nothrow_constructible<emstype, emstype&&,
               const typename emstype::allocator_type&>::value,
-              "except move constructor with allocator" );
+              "not noexcept move constructor with allocator" );
index acd84a8fcd0b60ff1d64d8f1a828b8a391024153..dc96236a6689a1282375acd458e3d96f1eaf1bd8 100644 (file)
@@ -29,6 +29,33 @@ static_assert( std::is_nothrow_constructible<stype,
               stype&&, const typename stype::allocator_type&>::value,
               "noexcept move constructor with allocator" );
 
+template<typename Type>
+  class not_noexcept_move_constructor_alloc : public std::allocator<Type>
+  {
+  public:
+    not_noexcept_move_constructor_alloc() noexcept { }
+
+    not_noexcept_move_constructor_alloc(
+       const not_noexcept_move_constructor_alloc& x) noexcept
+    : std::allocator<Type>(x)
+    { }
+
+    not_noexcept_move_constructor_alloc(
+       not_noexcept_move_constructor_alloc&& x) noexcept(false)
+    : std::allocator<Type>(std::move(x))
+    { }
+
+    template<typename _Tp1>
+      struct rebind
+      { typedef not_noexcept_move_constructor_alloc<_Tp1> other; };
+  };
+
+typedef std::set<int, std::less<int>,
+                not_noexcept_move_constructor_alloc<int>> astype;
+
+static_assert( std::is_nothrow_move_constructible<astype>::value,
+              "noexcept move constructor with not noexcept alloc" );
+
 struct not_noexcept_less
 {
   not_noexcept_less() = default;
@@ -42,6 +69,9 @@ struct not_noexcept_less
 
 typedef std::set<int, not_noexcept_less> estype;
 
+static_assert( !std::is_nothrow_move_constructible<estype>::value,
+              "not noexcept move constructor with not noexcept less" );
+
 static_assert( !std::is_nothrow_constructible<estype, estype&&,
               const typename estype::allocator_type&>::value,
-              "except move constructor with allocator" );
+              "not noexcept move constructor with allocator" );