[PATCH] D61366: [libcxx] [test] Don't assert that moved-from containers with non-POCMA allocators are empty.

Billy Robert O'Neal III via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 1 00:04:32 PDT 2019


BillyONeal created this revision.
BillyONeal added reviewers: mclow.lists, EricWF, ldionne.
Herald added a subscriber: dexonsmith.

The standard only requires that moved-from standard library types are in a 'valid but unspecified state', not that any moved-from container is empty. When the container is using a POCMA allocator, asserting that the moved-from container is empty is reasonable because the target container needs to take ownership of the memory buffers allocated from the source container's allocator. However, when the allocator is non-POCMA, the destination container must not take over any buffers, and effectively must copy the contents of the source container.

In the MSVC++ implementation, in this non-POCMA case, we do not clear() the source container, so that subsequent operations can reuse memory if the container is not immediately destroyed.


https://reviews.llvm.org/D61366

Files:
  test/std/containers/associative/map/map.cons/move_assign.pass.cpp
  test/std/containers/associative/multimap/multimap.cons/move_assign.pass.cpp
  test/std/containers/associative/multiset/multiset.cons/move_assign.pass.cpp
  test/std/containers/associative/set/set.cons/move_assign.pass.cpp


Index: test/std/containers/associative/set/set.cons/move_assign.pass.cpp
===================================================================
--- test/std/containers/associative/set/set.cons/move_assign.pass.cpp
+++ test/std/containers/associative/set/set.cons/move_assign.pass.cpp
@@ -100,7 +100,7 @@
         assert(m3 == m2);
         assert(m3.get_allocator() == A(5));
         assert(m3.key_comp() == C(5));
-        assert(m1.empty());
+        LIBCPP_ASSERT(m1.empty());
     }
     {
         typedef MoveOnly V;
Index: test/std/containers/associative/multiset/multiset.cons/move_assign.pass.cpp
===================================================================
--- test/std/containers/associative/multiset/multiset.cons/move_assign.pass.cpp
+++ test/std/containers/associative/multiset/multiset.cons/move_assign.pass.cpp
@@ -100,7 +100,7 @@
         assert(m3 == m2);
         assert(m3.get_allocator() == A(5));
         assert(m3.key_comp() == C(5));
-        assert(m1.empty());
+        LIBCPP_ASSERT(m1.empty());
     }
     {
         typedef MoveOnly V;
Index: test/std/containers/associative/multimap/multimap.cons/move_assign.pass.cpp
===================================================================
--- test/std/containers/associative/multimap/multimap.cons/move_assign.pass.cpp
+++ test/std/containers/associative/multimap/multimap.cons/move_assign.pass.cpp
@@ -102,7 +102,7 @@
         assert(m3 == m2);
         assert(m3.get_allocator() == A(5));
         assert(m3.key_comp() == C(5));
-        assert(m1.empty());
+        LIBCPP_ASSERT(m1.empty());
     }
     {
         typedef std::pair<MoveOnly, MoveOnly> V;
Index: test/std/containers/associative/map/map.cons/move_assign.pass.cpp
===================================================================
--- test/std/containers/associative/map/map.cons/move_assign.pass.cpp
+++ test/std/containers/associative/map/map.cons/move_assign.pass.cpp
@@ -102,7 +102,7 @@
         assert(m3 == m2);
         assert(m3.get_allocator() == A(5));
         assert(m3.key_comp() == C(5));
-        assert(m1.empty());
+        LIBCPP_ASSERT(m1.empty());
     }
     {
         typedef std::pair<MoveOnly, MoveOnly> V;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61366.197510.patch
Type: text/x-patch
Size: 2186 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190501/f1522bab/attachment.bin>


More information about the cfe-commits mailing list