[PATCH] Improve tests for vector and deque move-assignment

Jonathan Wakely jwakely@redhat.com
Wed Apr 26 19:25:00 GMT 2017


When I added is_always_equal the test allocators in these testcases
started inheriting it from their std::allocator base classes, so we
weren't testing that the exception specifications depended on the
propagate_on_container_move_assignment trait (they could have been
noexcept because of the inherited is_always_equal trait). Explicitly
set it to false instead, so we know the POCMA trait is being used.

The vector/52591.cc one also no longer tested the original problem in
PR 52591, because it didn't actually instantiate the move assignment
operator.

	* testsuite/23_containers/deque/allocator/move_assign-2.cc: Improve
	comment. Ensure first test works because allocator type propagates and
	not because is_always_equal is true.
	* testsuite/23_containers/vector/52591.cc: Likewise. Restore original
	testcase that instantiates the move-assignment operator.

Tested powerpc64le-linbux, committed to trunk.


-------------- next part --------------
commit c6ba628586b40f4e810b80559b8ea5be7cacbc09
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Apr 26 20:08:50 2017 +0100

    Improve tests for vector and deque move-assignment
    
    	* testsuite/23_containers/deque/allocator/move_assign-2.cc: Improve
    	comment. Ensure first test works because allocator type propagates and
    	not because is_always_equal is true.
    	* testsuite/23_containers/vector/52591.cc: Likewise. Restore original
    	testcase that instantiates the move-assignment operator.

diff --git a/libstdc++-v3/testsuite/23_containers/deque/allocator/move_assign-2.cc b/libstdc++-v3/testsuite/23_containers/deque/allocator/move_assign-2.cc
index c86c2c9..65c98f0 100644
--- a/libstdc++-v3/testsuite/23_containers/deque/allocator/move_assign-2.cc
+++ b/libstdc++-v3/testsuite/23_containers/deque/allocator/move_assign-2.cc
@@ -25,9 +25,9 @@
 #include <type_traits>
 
 
-// As an extension we allow move-assignment of std::deque when the element
-// type is not MoveAssignable, as long as the allocator type propagates or
-// is known to always compare equal.
+// Move-assignment of std::deque<T> is allowed for non-MoveAssignable T when
+// the allocator type propagates. As an extension we also allow it if the
+// allocator type is known to always compare equal.
 
 struct C
 {
@@ -43,6 +43,7 @@ struct A1 : std::allocator<T>
   template<typename U> A1(const A1<U>&) { }
 
   using propagate_on_container_move_assignment = std::true_type;
+  using is_always_equal = std::false_type;
 };
 
 void test01()
diff --git a/libstdc++-v3/testsuite/23_containers/vector/52591.cc b/libstdc++-v3/testsuite/23_containers/vector/52591.cc
index 3c0d39e..20938fa 100644
--- a/libstdc++-v3/testsuite/23_containers/vector/52591.cc
+++ b/libstdc++-v3/testsuite/23_containers/vector/52591.cc
@@ -23,15 +23,21 @@
 #include <memory>
 #include <type_traits>
 
-// As an extension we allow move-assignment of std::vector when the element
-// type is not MoveAssignable, as long as the allocator type propagates or
-// is known to always compare equal.
+// Move-assignment of std::vector<T> is allowed for non-MoveAssignable T when
+// the allocator type propagates. As an extension we also allow it if the
+// allocator type is known to always compare equal.
 
 struct C
 {
     C& operator=(C&&) = delete;
 };
 
+void test01()
+{
+    std::vector<C> a;
+    a = std::vector<C>();
+}
+
 template<typename T>
 struct A1 : std::allocator<T>
 {
@@ -41,9 +47,10 @@ struct A1 : std::allocator<T>
   template<typename U> A1(const A1<U>&) { }
 
   using propagate_on_container_move_assignment = std::true_type;
+  using is_always_equal = std::false_type;
 };
 
-void test01()
+void test02()
 {
   using test_type = std::vector<C, A1<C>>;
   static_assert(std::is_nothrow_move_assignable<test_type>::value,
@@ -62,7 +69,7 @@ struct A2 : std::allocator<T>
   using is_always_equal = std::true_type;
 };
 
-void test02()
+void test03()
 {
   using test_type = std::vector<C, A2<C>>;
   static_assert(std::is_nothrow_move_assignable<test_type>::value,


More information about the Libstdc++ mailing list