[libcxx-commits] [libcxx] [libc++][test] Cover move construction of allocators again (PR #110375)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sat Sep 28 10:15:14 PDT 2024


https://github.com/frederick-vs-ja created https://github.com/llvm/llvm-project/pull/110375

Previous PR #107344 fixed move constructor of `test_allocator` but dropped test coverage for move construction in some cases. This PR attempts to restore the test coverage.

Thanks @Quuxplusone for reminding.

>From 54fea07a5f7c31e0f84508888be61330666ba3bf Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Sun, 29 Sep 2024 01:12:27 +0800
Subject: [PATCH] [libc++][test] Cover move construction of allocators again

Previous PR fixed move constructor of `test_allocator` but dropped test
coverage for move construction in some cases. This PR attempts to
restore the test coverage.
---
 .../test/std/containers/associative/map/map.cons/move.pass.cpp  | 2 ++
 .../containers/associative/multimap/multimap.cons/move.pass.cpp | 2 ++
 .../containers/associative/multiset/multiset.cons/move.pass.cpp | 2 ++
 .../test/std/containers/associative/set/set.cons/move.pass.cpp  | 2 ++
 4 files changed, 8 insertions(+)

diff --git a/libcxx/test/std/containers/associative/map/map.cons/move.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/move.pass.cpp
index 0afe64a93d7bdd..7a883bed0d6e8d 100644
--- a/libcxx/test/std/containers/associative/map/map.cons/move.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.cons/move.pass.cpp
@@ -36,6 +36,7 @@ int main(int, char**)
         assert(std::distance(m.begin(), m.end()) == 0);
 
         assert(mo.get_allocator() == A(7));
+        assert(mo.get_allocator().get_id() == test_alloc_base::moved_value);
         assert(mo.key_comp() == C(5));
         assert(mo.size() == 0);
         assert(std::distance(mo.begin(), mo.end()) == 0);
@@ -66,6 +67,7 @@ int main(int, char**)
         assert(*std::next(m.begin(), 2) == V(3, 1));
 
         assert(mo.get_allocator() == A(7));
+        assert(mo.get_allocator().get_id() == test_alloc_base::moved_value);
         assert(mo.key_comp() == C(5));
         assert(mo.size() == 0);
         assert(std::distance(mo.begin(), mo.end()) == 0);
diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/move.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/move.pass.cpp
index 6458231e9a4d3c..8227b81f0c05c5 100644
--- a/libcxx/test/std/containers/associative/multimap/multimap.cons/move.pass.cpp
+++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/move.pass.cpp
@@ -36,6 +36,7 @@ int main(int, char**)
         assert(std::distance(m.begin(), m.end()) == 0);
 
         assert(mo.get_allocator() == A(7));
+        assert(mo.get_allocator().get_id() == test_alloc_base::moved_value);
         assert(mo.key_comp() == C(5));
         assert(mo.size() == 0);
         assert(std::distance(mo.begin(), mo.end()) == 0);
@@ -72,6 +73,7 @@ int main(int, char**)
         assert(*std::next(m.begin(), 8) == V(3, 2));
 
         assert(mo.get_allocator() == A(7));
+        assert(mo.get_allocator().get_id() == test_alloc_base::moved_value);
         assert(mo.key_comp() == C(5));
         assert(mo.size() == 0);
         assert(std::distance(mo.begin(), mo.end()) == 0);
diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/move.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/move.pass.cpp
index 65d297d3bfd45d..63898747180ae7 100644
--- a/libcxx/test/std/containers/associative/multiset/multiset.cons/move.pass.cpp
+++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/move.pass.cpp
@@ -36,6 +36,7 @@ int main(int, char**)
         assert(std::distance(m.begin(), m.end()) == 0);
 
         assert(mo.get_allocator() == A(7));
+        assert(mo.get_allocator().get_id() == test_alloc_base::moved_value);
         assert(mo.key_comp() == C(5));
         assert(mo.size() == 0);
         assert(std::distance(mo.begin(), mo.end()) == 0);
@@ -73,6 +74,7 @@ int main(int, char**)
         assert(*std::next(m.begin(), 8) == 3);
 
         assert(mo.get_allocator() == A(7));
+        assert(mo.get_allocator().get_id() == test_alloc_base::moved_value);
         assert(mo.key_comp() == C(5));
         assert(mo.size() == 0);
         assert(std::distance(mo.begin(), mo.end()) == 0);
diff --git a/libcxx/test/std/containers/associative/set/set.cons/move.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/move.pass.cpp
index 3824ea2d322b8a..3d6ab89ccf82fa 100644
--- a/libcxx/test/std/containers/associative/set/set.cons/move.pass.cpp
+++ b/libcxx/test/std/containers/associative/set/set.cons/move.pass.cpp
@@ -36,6 +36,7 @@ int main(int, char**)
         assert(std::distance(m.begin(), m.end()) == 0);
 
         assert(mo.get_allocator() == A(7));
+        assert(mo.get_allocator().get_id() == test_alloc_base::moved_value);
         assert(mo.key_comp() == C(5));
         assert(mo.size() == 0);
         assert(std::distance(mo.begin(), mo.end()) == 0);
@@ -67,6 +68,7 @@ int main(int, char**)
         assert(*std::next(m.begin(), 2) == 3);
 
         assert(mo.get_allocator() == A(7));
+        assert(mo.get_allocator().get_id() == test_alloc_base::moved_value);
         assert(mo.key_comp() == C(5));
         assert(mo.size() == 0);
         assert(std::distance(mo.begin(), mo.end()) == 0);



More information about the libcxx-commits mailing list