diff --git a/libcxx/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp --- a/libcxx/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp +++ b/libcxx/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp @@ -21,6 +21,8 @@ #include "min_allocator.h" #include "test_allocator.h" +test_allocator_statistics alloc_stats; + void test_basic() { { typedef std::pair V; @@ -77,7 +79,7 @@ typedef std::map, test_allocator > > Map; { LIBCPP_ASSERT(alloc_stats.alloc_count == 0); - Map s = {{1, 0}, {2, 0}, {3, 0}}; + Map s ({{1, 0}, {2, 0}, {3, 0}}, std::less(), test_allocator >(&alloc_stats)); LIBCPP_ASSERT(alloc_stats.alloc_count == 3); s = {{4, 0}, {4, 0}, {4, 0}, {4, 0}}; LIBCPP_ASSERT(alloc_stats.alloc_count == 1); 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 --- a/libcxx/test/std/containers/associative/map/map.cons/move.pass.cpp +++ b/libcxx/test/std/containers/associative/map/map.cons/move.pass.cpp @@ -35,7 +35,7 @@ assert(m.size() == 0); assert(distance(m.begin(), m.end()) == 0); - assert(mo.get_allocator() == A(test_alloc_base::moved_value)); + assert(mo.get_allocator() == A(moved_value)); assert(mo.key_comp() == C(5)); assert(mo.size() == 0); assert(distance(mo.begin(), mo.end()) == 0); @@ -65,7 +65,7 @@ assert(*next(m.begin()) == V(2, 1)); assert(*next(m.begin(), 2) == V(3, 1)); - assert(mo.get_allocator() == A(test_alloc_base::moved_value)); + assert(mo.get_allocator() == A(moved_value)); assert(mo.key_comp() == C(5)); assert(mo.size() == 0); assert(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 --- a/libcxx/test/std/containers/associative/multimap/multimap.cons/move.pass.cpp +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/move.pass.cpp @@ -35,7 +35,7 @@ assert(m.size() == 0); assert(distance(m.begin(), m.end()) == 0); - assert(mo.get_allocator() == A(test_alloc_base::moved_value)); + assert(mo.get_allocator() == A(moved_value)); assert(mo.key_comp() == C(5)); assert(mo.size() == 0); assert(distance(mo.begin(), mo.end()) == 0); @@ -71,7 +71,7 @@ assert(*next(m.begin(), 7) == V(3, 1.5)); assert(*next(m.begin(), 8) == V(3, 2)); - assert(mo.get_allocator() == A(test_alloc_base::moved_value)); + assert(mo.get_allocator() == A(moved_value)); assert(mo.key_comp() == C(5)); assert(mo.size() == 0); assert(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 --- a/libcxx/test/std/containers/associative/multiset/multiset.cons/move.pass.cpp +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/move.pass.cpp @@ -35,7 +35,7 @@ assert(m.size() == 0); assert(distance(m.begin(), m.end()) == 0); - assert(mo.get_allocator() == A(test_alloc_base::moved_value)); + assert(mo.get_allocator() == A(moved_value)); assert(mo.key_comp() == C(5)); assert(mo.size() == 0); assert(distance(mo.begin(), mo.end()) == 0); @@ -72,7 +72,7 @@ assert(*next(m.begin(), 7) == 3); assert(*next(m.begin(), 8) == 3); - assert(mo.get_allocator() == A(test_alloc_base::moved_value)); + assert(mo.get_allocator() == A(moved_value)); assert(mo.key_comp() == C(5)); assert(mo.size() == 0); assert(distance(mo.begin(), mo.end()) == 0); diff --git a/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp --- a/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp +++ b/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp @@ -21,6 +21,8 @@ #include "min_allocator.h" #include "test_allocator.h" +test_allocator_statistics alloc_stats; + void basic_test() { { typedef std::set C; @@ -58,7 +60,7 @@ typedef std::set, test_allocator > Set; { LIBCPP_ASSERT(alloc_stats.alloc_count == 0); - Set s = {1, 2, 3}; + Set s({1, 2, 3}, std::less(), test_allocator(&alloc_stats)); LIBCPP_ASSERT(alloc_stats.alloc_count == 3); s = {4, 4, 4, 4, 4}; LIBCPP_ASSERT(alloc_stats.alloc_count == 1); 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 --- a/libcxx/test/std/containers/associative/set/set.cons/move.pass.cpp +++ b/libcxx/test/std/containers/associative/set/set.cons/move.pass.cpp @@ -35,7 +35,7 @@ assert(m.size() == 0); assert(distance(m.begin(), m.end()) == 0); - assert(mo.get_allocator() == A(test_alloc_base::moved_value)); + assert(mo.get_allocator() == A(moved_value)); assert(mo.key_comp() == C(5)); assert(mo.size() == 0); assert(distance(mo.begin(), mo.end()) == 0); @@ -66,7 +66,7 @@ assert(*next(m.begin()) == 2); assert(*next(m.begin(), 2) == 3); - assert(mo.get_allocator() == A(test_alloc_base::moved_value)); + assert(mo.get_allocator() == A(moved_value)); assert(mo.key_comp() == C(5)); assert(mo.size() == 0); assert(distance(mo.begin(), mo.end()) == 0); diff --git a/libcxx/test/std/containers/container.requirements/container.requirements.general/allocator_move.pass.cpp b/libcxx/test/std/containers/container.requirements/container.requirements.general/allocator_move.pass.cpp --- a/libcxx/test/std/containers/container.requirements/container.requirements.general/allocator_move.pass.cpp +++ b/libcxx/test/std/containers/container.requirements/container.requirements.general/allocator_move.pass.cpp @@ -25,12 +25,14 @@ #include "test_macros.h" #include "test_allocator.h" +test_allocator_statistics alloc_stats; + template void test(int expected_num_allocs = 1) { { alloc_stats.clear(); using AllocT = typename C::allocator_type; - C v(AllocT(42, 101)); + C v(AllocT(42, 101, &alloc_stats)); assert(alloc_stats.count == expected_num_allocs); @@ -50,8 +52,8 @@ assert(alloc_stats.moved == num_stored_allocs); { const AllocT& a = v.get_allocator(); - assert(a.get_id() == test_alloc_base::moved_value); - assert(a.get_data() == test_alloc_base::moved_value); + assert(a.get_id() == moved_value); + assert(a.get_data() == moved_value); } { const AllocT& a = v2.get_allocator(); diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/move.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/move.pass.cpp --- a/libcxx/test/std/containers/sequences/deque/deque.cons/move.pass.cpp +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/move.pass.cpp @@ -37,7 +37,7 @@ assert(c2 == c3); assert(c1.size() == 0); assert(c3.get_allocator() == old_a); - assert(c1.get_allocator() == A(test_alloc_base::moved_value)); + assert(c1.get_allocator() == A(moved_value)); } { int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp --- a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp @@ -16,6 +16,8 @@ #include "test_allocator.h" #include +test_allocator_statistics alloc_stats; + // Flag that makes the copy constructor for CMyClass throw an exception static bool gCopyConstructorShouldThow = false; @@ -87,8 +89,8 @@ { typedef std::deque > C; - C vec; - C vec2(vec); + C vec((test_allocator(&alloc_stats))); + C vec2(vec, test_allocator(&alloc_stats)); alloc_stats.throw_after = 1; try { diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp --- a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp @@ -16,6 +16,8 @@ #include "test_macros.h" #include "test_allocator.h" +test_allocator_statistics alloc_stats; + // Flag that makes the copy constructor for CMyClass throw an exception static bool gCopyConstructorShouldThow = false; @@ -87,8 +89,8 @@ { typedef std::deque > C; - C vec; - C vec2(vec); + C vec((test_allocator(&alloc_stats))); + C vec2(vec, test_allocator(&alloc_stats)); alloc_stats.throw_after = 1; try { diff --git a/libcxx/test/std/containers/sequences/vector.bool/move.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/move.pass.cpp --- a/libcxx/test/std/containers/sequences/vector.bool/move.pass.cpp +++ b/libcxx/test/std/containers/sequences/vector.bool/move.pass.cpp @@ -18,11 +18,13 @@ #include "test_allocator.h" #include "min_allocator.h" +test_allocator_statistics alloc_stats; + int main(int, char**) { { - std::vector > l(test_allocator(5)); - std::vector > lo(test_allocator(5)); + std::vector > l(test_allocator(5, &alloc_stats)); + std::vector > lo(test_allocator(5, &alloc_stats)); for (int i = 1; i <= 3; ++i) { l.push_back(true); @@ -63,7 +65,7 @@ alloc_stats.clear(); using Vect = std::vector >; using AllocT = Vect::allocator_type; - Vect v(test_allocator(42, 101)); + Vect v(test_allocator(42, 101, &alloc_stats)); assert(alloc_stats.count == 1); { const AllocT& a = v.get_allocator(); @@ -80,8 +82,8 @@ assert(alloc_stats.moved == 1); { const AllocT& a = v.get_allocator(); - assert(a.get_id() == test_alloc_base::moved_value); - assert(a.get_data() == test_alloc_base::moved_value); + assert(a.get_id() == moved_value); + assert(a.get_data() == moved_value); } { const AllocT& a = v2.get_allocator(); diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/move.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/move.pass.cpp --- a/libcxx/test/std/containers/sequences/vector/vector.cons/move.pass.cpp +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/move.pass.cpp @@ -21,11 +21,13 @@ #include "min_allocator.h" #include "asan_testing.h" +test_allocator_statistics alloc_stats; + int main(int, char**) { { - std::vector > l(test_allocator(5)); - std::vector > lo(test_allocator(5)); + std::vector > l(test_allocator(5, &alloc_stats)); + std::vector > lo(test_allocator(5, &alloc_stats)); assert(is_contiguous_container_asan_correct(l)); assert(is_contiguous_container_asan_correct(lo)); for (int i = 1; i <= 3; ++i) @@ -102,7 +104,7 @@ { alloc_stats.clear(); using Vect = std::vector >; - Vect v(test_allocator(42, 101)); + Vect v(test_allocator(42, 101, &alloc_stats)); assert(alloc_stats.count == 1); assert(alloc_stats.copied == 1); assert(alloc_stats.moved == 0); @@ -120,8 +122,8 @@ assert(alloc_stats.moved == 1); { const test_allocator& a = v.get_allocator(); - assert(a.get_id() == test_alloc_base::moved_value); - assert(a.get_data() == test_alloc_base::moved_value); + assert(a.get_id() == moved_value); + assert(a.get_data() == moved_value); } { const test_allocator& a = v2.get_allocator(); diff --git a/libcxx/test/std/re/re.results/re.results.const/move.pass.cpp b/libcxx/test/std/re/re.results/re.results.const/move.pass.cpp --- a/libcxx/test/std/re/re.results/re.results.const/move.pass.cpp +++ b/libcxx/test/std/re/re.results/re.results.const/move.pass.cpp @@ -19,6 +19,8 @@ #include "test_macros.h" #include "test_allocator.h" +test_allocator_statistics alloc_stats; + template void test(const Allocator& a) @@ -40,9 +42,9 @@ test (std::allocator >()); test(std::allocator >()); - test (test_allocator >(3)); + test (test_allocator >(3, &alloc_stats)); assert(alloc_stats.moved == 1); - test(test_allocator >(3)); + test(test_allocator >(3, &alloc_stats)); assert(alloc_stats.moved == 2); return 0; diff --git a/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp @@ -18,6 +18,8 @@ #include "test_macros.h" +test_allocator_statistics alloc_stats; + template void test(S s) @@ -44,7 +46,7 @@ { { typedef std::basic_string, test_allocator > S; - S s; + S s((test_allocator(&alloc_stats))); test(s); s.assign(10, 'a'); s.erase(5); diff --git a/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp @@ -19,6 +19,7 @@ #include "test_allocator.h" #include "min_allocator.h" +test_allocator_statistics alloc_stats; template void @@ -44,9 +45,9 @@ #elif TEST_STD_VER >= 11 static_assert((noexcept(S()) == std::is_nothrow_move_constructible::value), "" ); #endif - test(S(), A(3)); - test(S("1"), A(5)); - test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7)); + test(S(), A(3, &alloc_stats)); + test(S("1"), A(5, &alloc_stats)); + test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7, &alloc_stats)); } int alloc_count = alloc_stats.alloc_count; @@ -58,8 +59,8 @@ #elif TEST_STD_VER >= 11 static_assert((noexcept(S()) == std::is_nothrow_move_constructible::value), "" ); #endif - S s1 ( "Twas brillig, and the slivy toves did gyre and gymbal in the wabe" ); - S s2 (std::move(s1), A(1)); + S s1 ( "Twas brillig, and the slivy toves did gyre and gymbal in the wabe", A(&alloc_stats)); + S s2 (std::move(s1), A(1, &alloc_stats)); } assert ( alloc_stats.alloc_count == alloc_count ); { diff --git a/libcxx/test/std/thread/futures/futures.promise/alloc_ctor.pass.cpp b/libcxx/test/std/thread/futures/futures.promise/alloc_ctor.pass.cpp --- a/libcxx/test/std/thread/futures/futures.promise/alloc_ctor.pass.cpp +++ b/libcxx/test/std/thread/futures/futures.promise/alloc_ctor.pass.cpp @@ -23,11 +23,13 @@ #include "test_allocator.h" #include "min_allocator.h" +test_allocator_statistics alloc_stats; + int main(int, char**) { assert(alloc_stats.alloc_count == 0); { - std::promise p(std::allocator_arg, test_allocator(42)); + std::promise p(std::allocator_arg, test_allocator(42, &alloc_stats)); assert(alloc_stats.alloc_count == 1); std::future f = p.get_future(); assert(alloc_stats.alloc_count == 1); @@ -35,7 +37,7 @@ } assert(alloc_stats.alloc_count == 0); { - std::promise p(std::allocator_arg, test_allocator(42)); + std::promise p(std::allocator_arg, test_allocator(42, &alloc_stats)); assert(alloc_stats.alloc_count == 1); std::future f = p.get_future(); assert(alloc_stats.alloc_count == 1); @@ -43,7 +45,7 @@ } assert(alloc_stats.alloc_count == 0); { - std::promise p(std::allocator_arg, test_allocator(42)); + std::promise p(std::allocator_arg, test_allocator(42, &alloc_stats)); assert(alloc_stats.alloc_count == 1); std::future f = p.get_future(); assert(alloc_stats.alloc_count == 1); diff --git a/libcxx/test/std/thread/futures/futures.promise/move_assign.pass.cpp b/libcxx/test/std/thread/futures/futures.promise/move_assign.pass.cpp --- a/libcxx/test/std/thread/futures/futures.promise/move_assign.pass.cpp +++ b/libcxx/test/std/thread/futures/futures.promise/move_assign.pass.cpp @@ -21,12 +21,14 @@ #include "test_macros.h" #include "test_allocator.h" +test_allocator_statistics alloc_stats; + int main(int, char**) { assert(alloc_stats.alloc_count == 0); { - std::promise p0(std::allocator_arg, test_allocator()); - std::promise p(std::allocator_arg, test_allocator()); + std::promise p0(std::allocator_arg, test_allocator(&alloc_stats)); + std::promise p(std::allocator_arg, test_allocator(&alloc_stats)); assert(alloc_stats.alloc_count == 2); p = std::move(p0); assert(alloc_stats.alloc_count == 1); @@ -48,8 +50,8 @@ } assert(alloc_stats.alloc_count == 0); { - std::promise p0(std::allocator_arg, test_allocator()); - std::promise p(std::allocator_arg, test_allocator()); + std::promise p0(std::allocator_arg, test_allocator(&alloc_stats)); + std::promise p(std::allocator_arg, test_allocator(&alloc_stats)); assert(alloc_stats.alloc_count == 2); p = std::move(p0); assert(alloc_stats.alloc_count == 1); @@ -71,8 +73,8 @@ } assert(alloc_stats.alloc_count == 0); { - std::promise p0(std::allocator_arg, test_allocator()); - std::promise p(std::allocator_arg, test_allocator()); + std::promise p0(std::allocator_arg, test_allocator(&alloc_stats)); + std::promise p(std::allocator_arg, test_allocator(&alloc_stats)); assert(alloc_stats.alloc_count == 2); p = std::move(p0); assert(alloc_stats.alloc_count == 1); diff --git a/libcxx/test/std/thread/futures/futures.promise/move_ctor.pass.cpp b/libcxx/test/std/thread/futures/futures.promise/move_ctor.pass.cpp --- a/libcxx/test/std/thread/futures/futures.promise/move_ctor.pass.cpp +++ b/libcxx/test/std/thread/futures/futures.promise/move_ctor.pass.cpp @@ -21,11 +21,13 @@ #include "test_macros.h" #include "test_allocator.h" +test_allocator_statistics alloc_stats; + int main(int, char**) { assert(alloc_stats.alloc_count == 0); { - std::promise p0(std::allocator_arg, test_allocator()); + std::promise p0(std::allocator_arg, test_allocator(&alloc_stats)); std::promise p(std::move(p0)); assert(alloc_stats.alloc_count == 1); std::future f = p.get_future(); @@ -46,7 +48,7 @@ } assert(alloc_stats.alloc_count == 0); { - std::promise p0(std::allocator_arg, test_allocator()); + std::promise p0(std::allocator_arg, test_allocator(&alloc_stats)); std::promise p(std::move(p0)); assert(alloc_stats.alloc_count == 1); std::future f = p.get_future(); @@ -67,7 +69,7 @@ } assert(alloc_stats.alloc_count == 0); { - std::promise p0(std::allocator_arg, test_allocator()); + std::promise p0(std::allocator_arg, test_allocator(&alloc_stats)); std::promise p(std::move(p0)); assert(alloc_stats.alloc_count == 1); std::future f = p.get_future(); diff --git a/libcxx/test/std/thread/futures/futures.promise/swap.pass.cpp b/libcxx/test/std/thread/futures/futures.promise/swap.pass.cpp --- a/libcxx/test/std/thread/futures/futures.promise/swap.pass.cpp +++ b/libcxx/test/std/thread/futures/futures.promise/swap.pass.cpp @@ -23,12 +23,14 @@ #include "test_macros.h" #include "test_allocator.h" +test_allocator_statistics alloc_stats; + int main(int, char**) { assert(alloc_stats.alloc_count == 0); { - std::promise p0(std::allocator_arg, test_allocator()); - std::promise p(std::allocator_arg, test_allocator()); + std::promise p0(std::allocator_arg, test_allocator(&alloc_stats)); + std::promise p(std::allocator_arg, test_allocator(&alloc_stats)); assert(alloc_stats.alloc_count == 2); p.swap(p0); assert(alloc_stats.alloc_count == 2); @@ -41,8 +43,8 @@ } assert(alloc_stats.alloc_count == 0); { - std::promise p0(std::allocator_arg, test_allocator()); - std::promise p(std::allocator_arg, test_allocator()); + std::promise p0(std::allocator_arg, test_allocator(&alloc_stats)); + std::promise p(std::allocator_arg, test_allocator(&alloc_stats)); assert(alloc_stats.alloc_count == 2); swap(p, p0); assert(alloc_stats.alloc_count == 2); @@ -55,7 +57,7 @@ } assert(alloc_stats.alloc_count == 0); { - std::promise p0(std::allocator_arg, test_allocator()); + std::promise p0(std::allocator_arg, test_allocator(&alloc_stats)); std::promise p; assert(alloc_stats.alloc_count == 1); p.swap(p0); @@ -69,7 +71,7 @@ } assert(alloc_stats.alloc_count == 0); { - std::promise p0(std::allocator_arg, test_allocator()); + std::promise p0(std::allocator_arg, test_allocator(&alloc_stats)); std::promise p; assert(alloc_stats.alloc_count == 1); swap(p, p0); diff --git a/libcxx/test/std/thread/futures/futures.shared_future/dtor.pass.cpp b/libcxx/test/std/thread/futures/futures.shared_future/dtor.pass.cpp --- a/libcxx/test/std/thread/futures/futures.shared_future/dtor.pass.cpp +++ b/libcxx/test/std/thread/futures/futures.shared_future/dtor.pass.cpp @@ -22,6 +22,8 @@ #include "test_macros.h" #include "test_allocator.h" +test_allocator_statistics alloc_stats; + int main(int, char**) { assert(alloc_stats.alloc_count == 0); @@ -29,7 +31,7 @@ typedef int T; std::shared_future f; { - std::promise p(std::allocator_arg, test_allocator()); + std::promise p(std::allocator_arg, test_allocator(&alloc_stats)); assert(alloc_stats.alloc_count == 1); f = p.get_future(); assert(alloc_stats.alloc_count == 1); @@ -43,7 +45,7 @@ typedef int& T; std::shared_future f; { - std::promise p(std::allocator_arg, test_allocator()); + std::promise p(std::allocator_arg, test_allocator(&alloc_stats)); assert(alloc_stats.alloc_count == 1); f = p.get_future(); assert(alloc_stats.alloc_count == 1); @@ -57,7 +59,7 @@ typedef void T; std::shared_future f; { - std::promise p(std::allocator_arg, test_allocator()); + std::promise p(std::allocator_arg, test_allocator(&alloc_stats)); assert(alloc_stats.alloc_count == 1); f = p.get_future(); assert(alloc_stats.alloc_count == 1); diff --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_func_alloc.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_func_alloc.pass.cpp --- a/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_func_alloc.pass.cpp +++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctor_func_alloc.pass.cpp @@ -25,6 +25,8 @@ #include "test_allocator.h" #include "min_allocator.h" +test_allocator_statistics alloc_stats; + class A { long data_; @@ -49,7 +51,7 @@ { { std::packaged_task p(std::allocator_arg, - test_allocator(), A(5)); + test_allocator(&alloc_stats), A(5)); assert(alloc_stats.alloc_count > 0); assert(p.valid()); std::future f = p.get_future(); @@ -64,7 +66,7 @@ { A a(5); std::packaged_task p(std::allocator_arg, - test_allocator(), a); + test_allocator(&alloc_stats), a); assert(alloc_stats.alloc_count > 0); assert(p.valid()); std::future f = p.get_future(); @@ -78,7 +80,7 @@ A::n_moves = 0; { A a(5); - std::packaged_task p(std::allocator_arg, test_allocator(), &func); + std::packaged_task p(std::allocator_arg, test_allocator(&alloc_stats), &func); assert(alloc_stats.alloc_count > 0); assert(p.valid()); std::future f = p.get_future(); @@ -90,7 +92,7 @@ A::n_moves = 0; { A a(5); - std::packaged_task p(std::allocator_arg, test_allocator(), func); + std::packaged_task p(std::allocator_arg, test_allocator(&alloc_stats), func); assert(alloc_stats.alloc_count > 0); assert(p.valid()); std::future f = p.get_future(); diff --git a/libcxx/test/std/thread/futures/futures.unique_future/dtor.pass.cpp b/libcxx/test/std/thread/futures/futures.unique_future/dtor.pass.cpp --- a/libcxx/test/std/thread/futures/futures.unique_future/dtor.pass.cpp +++ b/libcxx/test/std/thread/futures/futures.unique_future/dtor.pass.cpp @@ -22,6 +22,8 @@ #include "test_macros.h" #include "test_allocator.h" +test_allocator_statistics alloc_stats; + int main(int, char**) { assert(alloc_stats.alloc_count == 0); @@ -29,7 +31,7 @@ typedef int T; std::future f; { - std::promise p(std::allocator_arg, test_allocator()); + std::promise p(std::allocator_arg, test_allocator(&alloc_stats)); assert(alloc_stats.alloc_count == 1); f = p.get_future(); assert(alloc_stats.alloc_count == 1); @@ -43,7 +45,7 @@ typedef int& T; std::future f; { - std::promise p(std::allocator_arg, test_allocator()); + std::promise p(std::allocator_arg, test_allocator(&alloc_stats)); assert(alloc_stats.alloc_count == 1); f = p.get_future(); assert(alloc_stats.alloc_count == 1); @@ -57,7 +59,7 @@ typedef void T; std::future f; { - std::promise p(std::allocator_arg, test_allocator()); + std::promise p(std::allocator_arg, test_allocator(&alloc_stats)); assert(alloc_stats.alloc_count == 1); f = p.get_future(); assert(alloc_stats.alloc_count == 1); diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp --- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp @@ -25,6 +25,7 @@ #include "count_new.h" #include "../function_types.h" +test_allocator_statistics alloc_stats; #if TEST_STD_VER >= 11 struct RValueCallable { @@ -119,7 +120,7 @@ test_for_alloc(bare_alloc); } { - non_default_test_allocator non_default_alloc(42); + non_default_test_allocator non_default_alloc(42, &alloc_stats); test_for_alloc(non_default_alloc); } #if TEST_STD_VER >= 11 diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp @@ -17,6 +17,8 @@ #include "test_allocator.h" #include "min_allocator.h" +test_allocator_statistics alloc_stats; + struct A { static int count; @@ -31,7 +33,7 @@ int main(int, char**) { { - std::shared_ptr p(nullptr, test_deleter(3), test_allocator(5)); + std::shared_ptr p(nullptr, test_deleter(3), test_allocator(5, &alloc_stats)); assert(A::count == 0); assert(p.use_count() == 1); assert(p.get() == 0); diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp @@ -17,6 +17,8 @@ #include "deleter_types.h" #include "test_allocator.h" +test_allocator_statistics alloc_stats; + struct A { static int count; @@ -33,7 +35,7 @@ try { alloc_stats.throw_after = 0; - std::shared_ptr p(nullptr, test_deleter(3), test_allocator(5)); + std::shared_ptr p(nullptr, test_deleter(3), test_allocator(5, &alloc_stats)); assert(false); } catch (std::bad_alloc&) diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp @@ -17,6 +17,8 @@ #include "test_allocator.h" #include "min_allocator.h" +test_allocator_statistics alloc_stats; + struct A { static int count; @@ -64,7 +66,7 @@ { { A* ptr = new A; - std::shared_ptr p(ptr, test_deleter(3), test_allocator(5)); + std::shared_ptr p(ptr, test_deleter(3), test_allocator(5, &alloc_stats)); assert(A::count == 1); assert(p.use_count() == 1); assert(p.get() == ptr); diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp @@ -17,6 +17,8 @@ #include "deleter_types.h" #include "test_allocator.h" +test_allocator_statistics alloc_stats; + struct A { static int count; @@ -34,7 +36,7 @@ try { alloc_stats.throw_after = 0; - std::shared_ptr p(ptr, test_deleter(3), test_allocator(5)); + std::shared_ptr p(ptr, test_deleter(3), test_allocator(5, &alloc_stats)); assert(false); } catch (std::bad_alloc&) diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp @@ -21,6 +21,8 @@ #include "test_allocator.h" #include "min_allocator.h" +test_allocator_statistics alloc_stats; + #if TEST_STD_VER >= 11 #define DELETE_FUNCTION = delete #else @@ -150,7 +152,7 @@ { int i = 67; char c = 'e'; - std::shared_ptr p = std::allocate_shared(test_allocator(54), i, c); + std::shared_ptr p = std::allocate_shared(test_allocator(54, &alloc_stats), i, c); assert(alloc_stats.alloc_count == 1); assert(A::count == 1); assert(p->get_int() == 67); diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp @@ -18,6 +18,8 @@ #include "deleter_types.h" #include "test_allocator.h" +test_allocator_statistics alloc_stats; + struct B { static int count; @@ -46,7 +48,7 @@ { std::shared_ptr p(new B); A* ptr = new A; - p.reset(ptr, test_deleter(3), test_allocator(4)); + p.reset(ptr, test_deleter(3), test_allocator(4, &alloc_stats)); assert(A::count == 1); assert(B::count == 1); assert(p.use_count() == 1); @@ -69,7 +71,7 @@ { std::shared_ptr p; A* ptr = new A; - p.reset(ptr, test_deleter(3), test_allocator(4)); + p.reset(ptr, test_deleter(3), test_allocator(4, &alloc_stats)); assert(A::count == 1); assert(B::count == 1); assert(p.use_count() == 1); diff --git a/libcxx/test/support/test_allocator.h b/libcxx/test/support/test_allocator.h --- a/libcxx/test/support/test_allocator.h +++ b/libcxx/test/support/test_allocator.h @@ -21,287 +21,352 @@ #include "test_macros.h" template -inline typename std::allocator_traits::size_type -alloc_max_size(Alloc const &a) { +inline typename std::allocator_traits::size_type alloc_max_size(Alloc const& a) { typedef std::allocator_traits AT; return AT::max_size(a); } -struct test_allocator_statistics -{ - int time_to_throw = 0; - int throw_after = INT_MAX; - int count = 0; - int alloc_count = 0; - int copied = 0; - int moved = 0; - int converted = 0; - - TEST_CONSTEXPR_CXX14 void clear() { - assert(count == 0 && "clearing leaking allocator data?"); - count = 0; - time_to_throw = 0; - alloc_count = 0; - throw_after = INT_MAX; - clear_ctor_counters(); - } +struct test_allocator_statistics { + int time_to_throw = 0; + int throw_after = INT_MAX; + int count = 0; + int alloc_count = 0; + int copied = 0; + int moved = 0; + int converted = 0; + + TEST_CONSTEXPR_CXX14 void clear() { + assert(count == 0 && "clearing leaking allocator data?"); + count = 0; + time_to_throw = 0; + alloc_count = 0; + throw_after = INT_MAX; + clear_ctor_counters(); + } - TEST_CONSTEXPR_CXX14 void clear_ctor_counters() { - copied = 0; - moved = 0; - converted = 0; - } + TEST_CONSTEXPR_CXX14 void clear_ctor_counters() { + copied = 0; + moved = 0; + converted = 0; + } }; -test_allocator_statistics alloc_stats; +const int destructed_value = -1; +const int default_value = 0; +const int moved_value = INT_MAX; + +template +class test_allocator { + int data_ = 0; // participates in equality + int id_ = 0; // unique identifier, doesn't participate in equality + test_allocator_statistics* stats_ = nullptr; + + template + friend class test_allocator; -class test_alloc_base -{ public: - TEST_CONSTEXPR test_alloc_base(test_allocator_statistics* stats) : stats_(stats) {} + typedef unsigned size_type; + typedef int difference_type; + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef typename std::add_lvalue_reference::type reference; + typedef typename std::add_lvalue_reference::type const_reference; + + template + struct rebind { + typedef test_allocator other; + }; + + TEST_CONSTEXPR test_allocator() TEST_NOEXCEPT = default; + + TEST_CONSTEXPR_CXX14 test_allocator(test_allocator_statistics* stats) TEST_NOEXCEPT : stats_(stats) { + if (stats_ != nullptr) + ++stats_->count; + } - const static int destructed_value = -1; - const static int default_value = 0; - const static int moved_value = INT_MAX; + TEST_CONSTEXPR explicit test_allocator(int data) TEST_NOEXCEPT : data_(data) {} -protected: - test_allocator_statistics* stats_; -}; + TEST_CONSTEXPR_CXX14 explicit test_allocator(int data, test_allocator_statistics* stats) TEST_NOEXCEPT : data_(data), + stats_(stats) { + if (stats != nullptr) + ++stats_->count; + } -template -class test_allocator - : public test_alloc_base -{ - int data_; // participates in equality - int id_; // unique identifier, doesn't participate in equality - template friend class test_allocator; -public: + TEST_CONSTEXPR explicit test_allocator(int data, int id) : data_(data), id_(id) {} + + TEST_CONSTEXPR_CXX14 explicit test_allocator(int data, int id, test_allocator_statistics* stats) TEST_NOEXCEPT + : data_(data), + id_(id), + stats_(stats) { + if (stats_ != nullptr) + ++stats_->count; + } - typedef unsigned size_type; - typedef int difference_type; - typedef T value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef typename std::add_lvalue_reference::type reference; - typedef typename std::add_lvalue_reference::type const_reference; - - template struct rebind {typedef test_allocator other;}; - - TEST_CONSTEXPR_CXX14 test_allocator(test_allocator_statistics* stats = &alloc_stats) TEST_NOEXCEPT - : test_alloc_base(stats), data_(0), id_(0) - {++stats_->count;} - TEST_CONSTEXPR_CXX14 explicit test_allocator(int i, int id = 0, test_allocator_statistics* stats = &alloc_stats) TEST_NOEXCEPT - : test_alloc_base(stats), data_(i), id_(id) - {++stats_->count;} - TEST_CONSTEXPR_CXX14 test_allocator(const test_allocator& a) TEST_NOEXCEPT : test_alloc_base(a.stats_), data_(a.data_), - id_(a.id_) { + TEST_CONSTEXPR_CXX14 explicit test_allocator(const test_allocator& a) TEST_NOEXCEPT : data_(a.data_), + id_(a.id_), + stats_(a.stats_) { + assert(a.data_ != destructed_value && a.id_ != destructed_value && "copying from destroyed allocator"); + if (stats_ != nullptr) { ++stats_->count; ++stats_->copied; - assert(a.data_ != destructed_value && a.id_ != destructed_value && - "copying from destroyed allocator"); } + } + #if TEST_STD_VER >= 11 - TEST_CONSTEXPR_CXX14 test_allocator(test_allocator&& a) TEST_NOEXCEPT : test_alloc_base(a.stats_), data_(a.data_), - id_(a.id_) { + TEST_CONSTEXPR_CXX14 test_allocator(test_allocator&& a) TEST_NOEXCEPT : data_(a.data_), id_(a.id_), stats_(a.stats_) { + if (stats_ != nullptr) { ++stats_->count; ++stats_->moved; - assert(a.data_ != destructed_value && a.id_ != destructed_value && - "moving from destroyed allocator"); - a.data_ = moved_value; - a.id_ = moved_value; } + assert(a.data_ != destructed_value && a.id_ != destructed_value && "moving from destroyed allocator"); + a.data_ = moved_value; + a.id_ = moved_value; + } #endif - template - TEST_CONSTEXPR_CXX14 test_allocator(const test_allocator& a) TEST_NOEXCEPT - : test_alloc_base(a.stats_), data_(a.data_), id_(a.id_) { + + template + TEST_CONSTEXPR_CXX14 test_allocator(const test_allocator& a) TEST_NOEXCEPT : data_(a.data_), + id_(a.id_), + stats_(a.stats_) { + if (stats_ != nullptr) { ++stats_->count; ++stats_->converted; } - TEST_CONSTEXPR_CXX20 ~test_allocator() TEST_NOEXCEPT { - assert(data_ >= 0); assert(id_ >= 0); + } + + TEST_CONSTEXPR_CXX20 ~test_allocator() TEST_NOEXCEPT { + assert(data_ >= 0); + assert(id_ >= 0); + if (stats_ != nullptr) --stats_->count; - data_ = destructed_value; - id_ = destructed_value; + data_ = destructed_value; + id_ = destructed_value; + } + + TEST_CONSTEXPR pointer address(reference x) const { return &x; } + TEST_CONSTEXPR const_pointer address(const_reference x) const { return &x; } + + TEST_CONSTEXPR_CXX14 pointer allocate(size_type n, const void* = 0) { + assert(data_ >= 0); + if (stats_ != nullptr) { + if (stats_->time_to_throw >= stats_->throw_after) + TEST_THROW(std::bad_alloc()); + ++stats_->time_to_throw; + ++stats_->alloc_count; } - TEST_CONSTEXPR pointer address(reference x) const {return &x;} - TEST_CONSTEXPR const_pointer address(const_reference x) const {return &x;} - TEST_CONSTEXPR_CXX14 pointer allocate(size_type n, const void* = 0) - { - assert(data_ >= 0); - if (stats_->time_to_throw >= stats_->throw_after) { -#ifndef TEST_HAS_NO_EXCEPTIONS - throw std::bad_alloc(); -#else - std::terminate(); -#endif - } - ++stats_->time_to_throw; - ++stats_->alloc_count; - return (pointer)::operator new(n * sizeof(T)); - } - TEST_CONSTEXPR_CXX14 void deallocate(pointer p, size_type) - {assert(data_ >= 0); --stats_->alloc_count; ::operator delete((void*)p);} - TEST_CONSTEXPR size_type max_size() const TEST_NOEXCEPT - {return UINT_MAX / sizeof(T);} + return (pointer)::operator new(n * sizeof(T)); + } + + TEST_CONSTEXPR_CXX14 void deallocate(pointer p, size_type) { + assert(data_ >= 0); + if (stats_ != nullptr) + --stats_->alloc_count; + ::operator delete((void*)p); + } + + TEST_CONSTEXPR size_type max_size() const TEST_NOEXCEPT { return UINT_MAX / sizeof(T); } + #if TEST_STD_VER < 11 - void construct(pointer p, const T& val) - {::new(static_cast(p)) T(val);} + void construct(pointer p, const T& val) { ::new (static_cast(p)) T(val); } #else - template TEST_CONSTEXPR_CXX14 void construct(pointer p, U&& val) - {::new(static_cast(p)) T(std::forward(val));} + template + TEST_CONSTEXPR_CXX14 void construct(pointer p, U&& val) { + ::new (static_cast(p)) T(std::forward(val)); + } #endif - TEST_CONSTEXPR_CXX14 void destroy(pointer p) - {p->~T();} - TEST_CONSTEXPR friend bool operator==(const test_allocator& x, const test_allocator& y) - {return x.data_ == y.data_;} - TEST_CONSTEXPR friend bool operator!=(const test_allocator& x, const test_allocator& y) - {return !(x == y);} - - TEST_CONSTEXPR int get_data() const { return data_; } - TEST_CONSTEXPR int get_id() const { return id_; } + + TEST_CONSTEXPR_CXX14 void destroy(pointer p) { p->~T(); } + TEST_CONSTEXPR friend bool operator==(const test_allocator& x, const test_allocator& y) { return x.data_ == y.data_; } + TEST_CONSTEXPR friend bool operator!=(const test_allocator& x, const test_allocator& y) { return !(x == y); } + + TEST_CONSTEXPR int get_data() const { return data_; } + TEST_CONSTEXPR int get_id() const { return id_; } }; template -class non_default_test_allocator - : public test_alloc_base -{ - int data_; +class non_default_test_allocator { + int data_ = 0; + test_allocator_statistics* stats_ = nullptr; + + template + friend class non_default_test_allocator; - template friend class non_default_test_allocator; public: + typedef unsigned size_type; + typedef int difference_type; + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef typename std::add_lvalue_reference::type reference; + typedef typename std::add_lvalue_reference::type const_reference; + + template + struct rebind { + typedef non_default_test_allocator other; + }; + + // non_default_test_allocator() TEST_NOEXCEPT : data_(0) {++count;} + explicit non_default_test_allocator(int i, test_allocator_statistics* stats = nullptr) TEST_NOEXCEPT : data_(i), + stats_(stats) { + if (stats_ != nullptr) { + ++stats_->count; + } + } + + non_default_test_allocator(const non_default_test_allocator& a) TEST_NOEXCEPT : data_(a.data_), stats_(a.stats_) { + if (stats_ != nullptr) + ++stats_->count; + } + + template + non_default_test_allocator(const non_default_test_allocator& a) TEST_NOEXCEPT : data_(a.data_), stats_(a.stats_) { + if (stats_ != nullptr) + ++stats_->count; + } + + ~non_default_test_allocator() TEST_NOEXCEPT { + assert(data_ >= 0); + if (stats_ != nullptr) + --stats_->count; + data_ = -1; + } + + pointer address(reference x) const { return &x; } + const_pointer address(const_reference x) const { return &x; } + + pointer allocate(size_type n, const void* = 0) { + assert(data_ >= 0); + if (stats_ != nullptr) { + if (stats_->time_to_throw >= stats_->throw_after) + TEST_THROW(std::bad_alloc()); + ++stats_->time_to_throw; + ++stats_->alloc_count; + } + return (pointer)::operator new(n * sizeof(T)); + } + void deallocate(pointer p, size_type) { + assert(data_ >= 0); + if (stats_ != nullptr) + --stats_->alloc_count; + ::operator delete((void*)p); + } + + size_type max_size() const TEST_NOEXCEPT { return UINT_MAX / sizeof(T); } - typedef unsigned size_type; - typedef int difference_type; - typedef T value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef typename std::add_lvalue_reference::type reference; - typedef typename std::add_lvalue_reference::type const_reference; - - template struct rebind {typedef non_default_test_allocator other;}; - -// non_default_test_allocator() TEST_NOEXCEPT : data_(0) {++count;} - explicit non_default_test_allocator(int i, test_allocator_statistics* stats = &alloc_stats) TEST_NOEXCEPT - : test_alloc_base(stats), data_(i) - {++stats_->count;} - non_default_test_allocator(const non_default_test_allocator& a) TEST_NOEXCEPT - : test_alloc_base(a.stats_), data_(a.data_) {++stats_->count;} - template non_default_test_allocator(const non_default_test_allocator& a) TEST_NOEXCEPT - : test_alloc_base(a.stats_), data_(a.data_) {++stats_->count;} - ~non_default_test_allocator() TEST_NOEXCEPT {assert(data_ >= 0); --stats_->count; data_ = -1;} - pointer address(reference x) const {return &x;} - const_pointer address(const_reference x) const {return &x;} - pointer allocate(size_type n, const void* = 0) - { - assert(data_ >= 0); - if (stats_->time_to_throw >= stats_->throw_after) { -#ifndef TEST_HAS_NO_EXCEPTIONS - throw std::bad_alloc(); -#else - std::terminate(); -#endif - } - ++stats_->time_to_throw; - ++stats_->alloc_count; - return (pointer)::operator new (n * sizeof(T)); - } - void deallocate(pointer p, size_type) - {assert(data_ >= 0); --stats_->alloc_count; ::operator delete((void*)p); } - size_type max_size() const TEST_NOEXCEPT - {return UINT_MAX / sizeof(T);} #if TEST_STD_VER < 11 - void construct(pointer p, const T& val) - {::new(static_cast(p)) T(val);} + void construct(pointer p, const T& val) { ::new (static_cast(p)) T(val); } #else - template void construct(pointer p, U&& val) - {::new(static_cast(p)) T(std::forward(val));} + template + void construct(pointer p, U&& val) { + ::new (static_cast(p)) T(std::forward(val)); + } #endif - void destroy(pointer p) {p->~T();} - friend bool operator==(const non_default_test_allocator& x, const non_default_test_allocator& y) - {return x.data_ == y.data_;} - friend bool operator!=(const non_default_test_allocator& x, const non_default_test_allocator& y) - {return !(x == y);} + void destroy(pointer p) { p->~T(); } + + friend bool operator==(const non_default_test_allocator& x, const non_default_test_allocator& y) { + return x.data_ == y.data_; + } + + friend bool operator!=(const non_default_test_allocator& x, const non_default_test_allocator& y) { return !(x == y); } }; template <> -class test_allocator - : public test_alloc_base -{ - int data_; - int id_; +class test_allocator { + int data_ = 0; + int id_ = 0; + test_allocator_statistics* stats_ = nullptr; + + template + friend class test_allocator; - template friend class test_allocator; public: + typedef unsigned size_type; + typedef int difference_type; + typedef void value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + + template + struct rebind { + typedef test_allocator other; + }; - typedef unsigned size_type; - typedef int difference_type; - typedef void value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - - template struct rebind {typedef test_allocator other;}; - - test_allocator(test_allocator_statistics* stats = &alloc_stats) TEST_NOEXCEPT : test_alloc_base(stats), data_(0), id_(0) {} - explicit test_allocator(int i, int id = 0, test_allocator_statistics* stats = &alloc_stats) TEST_NOEXCEPT : test_alloc_base(stats), data_(i), id_(id) {} - test_allocator(const test_allocator& a) TEST_NOEXCEPT - : test_alloc_base(a.stats_), data_(a.data_), id_(a.id_) {} - template test_allocator(const test_allocator& a) TEST_NOEXCEPT - : test_alloc_base(a.stats_), data_(a.data_), id_(a.id_) {} - ~test_allocator() TEST_NOEXCEPT {data_ = -1; id_ = -1; } - - int get_id() const { return id_; } - int get_data() const { return data_; } - - friend bool operator==(const test_allocator& x, const test_allocator& y) - {return x.data_ == y.data_;} - friend bool operator!=(const test_allocator& x, const test_allocator& y) - {return !(x == y);} + TEST_CONSTEXPR test_allocator() TEST_NOEXCEPT = default; + + TEST_CONSTEXPR_CXX14 test_allocator(test_allocator_statistics* stats) TEST_NOEXCEPT : stats_(stats) {} + + TEST_CONSTEXPR explicit test_allocator(int data) TEST_NOEXCEPT : data_(data) {} + + TEST_CONSTEXPR explicit test_allocator(int data, test_allocator_statistics* stats) TEST_NOEXCEPT : data_(data), + stats_(stats) {} + + TEST_CONSTEXPR explicit test_allocator(int data, int id) : data_(data), id_(id) {} + + TEST_CONSTEXPR_CXX14 explicit test_allocator(int data, int id, test_allocator_statistics* stats) TEST_NOEXCEPT + : data_(data), + id_(id), + stats_(stats) {} + + TEST_CONSTEXPR_CXX14 explicit test_allocator(const test_allocator& a) TEST_NOEXCEPT : data_(a.data_), + id_(a.id_), + stats_(a.stats_) {} + + template + TEST_CONSTEXPR_CXX14 test_allocator(const test_allocator& a) TEST_NOEXCEPT : data_(a.data_), + id_(a.id_), + stats_(a.stats_) {} + + ~test_allocator() TEST_NOEXCEPT { + data_ = -1; + id_ = -1; + } + + int get_id() const { return id_; } + int get_data() const { return data_; } + + friend bool operator==(const test_allocator& x, const test_allocator& y) { return x.data_ == y.data_; } + friend bool operator!=(const test_allocator& x, const test_allocator& y) { return !(x == y); } }; template -class other_allocator -{ - int data_; +class other_allocator { + int data_; - template friend class other_allocator; + template + friend class other_allocator; public: - typedef T value_type; + typedef T value_type; - other_allocator() : data_(-1) {} - explicit other_allocator(int i) : data_(i) {} - template other_allocator(const other_allocator& a) - : data_(a.data_) {} - T* allocate(std::size_t n) - {return (T*)::operator new(n * sizeof(T));} - void deallocate(T* p, std::size_t) - {::operator delete((void*)p);} + other_allocator() : data_(-1) {} + explicit other_allocator(int i) : data_(i) {} + template + other_allocator(const other_allocator& a) : data_(a.data_) {} + T* allocate(std::size_t n) { return (T*)::operator new(n * sizeof(T)); } + void deallocate(T* p, std::size_t) { ::operator delete((void*)p); } - other_allocator select_on_container_copy_construction() const - {return other_allocator(-2);} + other_allocator select_on_container_copy_construction() const { return other_allocator(-2); } - friend bool operator==(const other_allocator& x, const other_allocator& y) - {return x.data_ == y.data_;} - friend bool operator!=(const other_allocator& x, const other_allocator& y) - {return !(x == y);} + friend bool operator==(const other_allocator& x, const other_allocator& y) { return x.data_ == y.data_; } + friend bool operator!=(const other_allocator& x, const other_allocator& y) { return !(x == y); } - typedef std::true_type propagate_on_container_copy_assignment; - typedef std::true_type propagate_on_container_move_assignment; - typedef std::true_type propagate_on_container_swap; + typedef std::true_type propagate_on_container_copy_assignment; + typedef std::true_type propagate_on_container_move_assignment; + typedef std::true_type propagate_on_container_swap; #if TEST_STD_VER < 11 - std::size_t max_size() const - {return UINT_MAX / sizeof(T);} + std::size_t max_size() const { return UINT_MAX / sizeof(T); } #endif - }; #if TEST_STD_VER >= 11 struct Ctor_Tag {}; -template class TaggingAllocator; +template +class TaggingAllocator; struct Tag_X { // All constructors must be passed the Tag type. @@ -314,8 +379,8 @@ Tag_X(Ctor_Tag, Tag_X&&) {} // EmplaceConstructible into vector> from args. - template - Tag_X(Ctor_Tag, Args&&...) { } + template + Tag_X(Ctor_Tag, Args&&...) {} // not DefaultConstructible, CopyConstructible or MoveConstructible. Tag_X() = delete; @@ -330,48 +395,50 @@ private: // Not Destructible. - ~Tag_X() { } + ~Tag_X() {} // Erasable from vector>. friend class TaggingAllocator; }; - -template +template class TaggingAllocator { public: - using value_type = T; - TaggingAllocator() = default; + using value_type = T; + TaggingAllocator() = default; - template - TaggingAllocator(const TaggingAllocator&) { } + template + TaggingAllocator(const TaggingAllocator&) {} - T* allocate(std::size_t n) { return std::allocator{}.allocate(n); } + T* allocate(std::size_t n) { return std::allocator{}.allocate(n); } - void deallocate(T* p, std::size_t n) { std::allocator{}.deallocate(p, n); } + void deallocate(T* p, std::size_t n) { std::allocator{}.deallocate(p, n); } - template - void construct(Tag_X* p, Args&&... args) - { ::new((void*)p) Tag_X(Ctor_Tag{}, std::forward(args)...); } + template + void construct(Tag_X* p, Args&&... args) { + ::new ((void*)p) Tag_X(Ctor_Tag{}, std::forward(args)...); + } - template - void construct(U* p, Args&&... args) - { ::new((void*)p) U(std::forward(args)...); } + template + void construct(U* p, Args&&... args) { + ::new ((void*)p) U(std::forward(args)...); + } - template - void destroy(U* p) - { p->~U(); } + template + void destroy(U* p) { + p->~U(); + } }; -template -bool -operator==(const TaggingAllocator&, const TaggingAllocator&) -{ return true; } +template +bool operator==(const TaggingAllocator&, const TaggingAllocator&) { + return true; +} -template -bool -operator!=(const TaggingAllocator&, const TaggingAllocator&) -{ return false; } +template +bool operator!=(const TaggingAllocator&, const TaggingAllocator&) { + return false; +} #endif template @@ -382,10 +449,10 @@ limited_alloc_handle() : outstanding_(0), last_alloc_(nullptr) {} template - T *allocate(std::size_t N) { + T* allocate(std::size_t N) { if (N + outstanding_ > MaxAllocs) TEST_THROW(std::bad_alloc()); - last_alloc_ = ::operator new(N*sizeof(T)); + last_alloc_ = ::operator new(N * sizeof(T)); outstanding_ += N; return static_cast(last_alloc_); } @@ -401,52 +468,52 @@ }; template -class limited_allocator -{ - template friend class limited_allocator; - typedef limited_alloc_handle BuffT; - std::shared_ptr handle_; +class limited_allocator { + template + friend class limited_allocator; + typedef limited_alloc_handle BuffT; + std::shared_ptr handle_; + public: - typedef T value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; - template struct rebind { typedef limited_allocator other; }; + template + struct rebind { + typedef limited_allocator other; + }; - limited_allocator() : handle_(new BuffT) {} + limited_allocator() : handle_(new BuffT) {} - limited_allocator(limited_allocator const& other) : handle_(other.handle_) {} + limited_allocator(limited_allocator const& other) : handle_(other.handle_) {} - template - explicit limited_allocator(limited_allocator const& other) - : handle_(other.handle_) {} + template + explicit limited_allocator(limited_allocator const& other) : handle_(other.handle_) {} private: - limited_allocator& operator=(const limited_allocator&);// = delete; + limited_allocator& operator=(const limited_allocator&); // = delete; public: - pointer allocate(size_type n) { return handle_->template allocate(n); } - void deallocate(pointer p, size_type n) { handle_->deallocate(p, n); } - size_type max_size() const {return N;} + pointer allocate(size_type n) { return handle_->template allocate(n); } + void deallocate(pointer p, size_type n) { handle_->deallocate(p, n); } + size_type max_size() const { return N; } - BuffT* getHandle() const { return handle_.get(); } + BuffT* getHandle() const { return handle_.get(); } }; template -inline bool operator==(limited_allocator const& LHS, - limited_allocator const& RHS) { +inline bool operator==(limited_allocator const& LHS, limited_allocator const& RHS) { return LHS.getHandle() == RHS.getHandle(); } template -inline bool operator!=(limited_allocator const& LHS, - limited_allocator const& RHS) { +inline bool operator!=(limited_allocator const& LHS, limited_allocator const& RHS) { return !(LHS == RHS); } - #endif // TEST_ALLOCATOR_H