Index: test/std/utilities/allocator.adaptor/allocator.adaptor.members/allocate_size.pass.cpp =================================================================== --- test/std/utilities/allocator.adaptor/allocator.adaptor.members/allocate_size.pass.cpp +++ test/std/utilities/allocator.adaptor/allocator.adaptor.members/allocate_size.pass.cpp @@ -27,22 +27,22 @@ typedef std::scoped_allocator_adaptor> A; A a; A1::allocate_called = false; - assert(a.allocate(10) == (int*)10); - assert(A1::allocate_called == true); + a.allocate(10); + assert(A1::allocate_called == 10); } { typedef std::scoped_allocator_adaptor, A2> A; A a; A1::allocate_called = false; - assert(a.allocate(10) == (int*)10); - assert(A1::allocate_called == true); + a.allocate(10); + assert(A1::allocate_called == 10); } { typedef std::scoped_allocator_adaptor, A2, A3> A; A a; A1::allocate_called = false; - assert(a.allocate(10) == (int*)10); - assert(A1::allocate_called == true); + a.allocate(10); + assert(A1::allocate_called == 10); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES Index: test/std/utilities/allocator.adaptor/allocator.adaptor.members/allocate_size_hint.pass.cpp =================================================================== --- test/std/utilities/allocator.adaptor/allocator.adaptor.members/allocate_size_hint.pass.cpp +++ test/std/utilities/allocator.adaptor/allocator.adaptor.members/allocate_size_hint.pass.cpp @@ -27,44 +27,44 @@ typedef std::scoped_allocator_adaptor> A; A a; A1::allocate_called = false; - assert(a.allocate(10, (const void*)0) == (int*)10); - assert(A1::allocate_called == true); + a.allocate(10, (const void*)0); + assert(A1::allocate_called == 10); } { typedef std::scoped_allocator_adaptor, A2> A; A a; A1::allocate_called = false; - assert(a.allocate(10, (const void*)10) == (int*)10); - assert(A1::allocate_called == true); + a.allocate(10, (const void*)10); + assert(A1::allocate_called == 10); } { typedef std::scoped_allocator_adaptor, A2, A3> A; A a; A1::allocate_called = false; - assert(a.allocate(10, (const void*)20) == (int*)10); - assert(A1::allocate_called == true); + a.allocate(10, (const void*)20); + assert(A1::allocate_called == 10); } { typedef std::scoped_allocator_adaptor> A; A a; - A2::allocate_called = false; - assert(a.allocate(10, (const void*)0) == (int*)0); - assert(A2::allocate_called == true); + A2::allocate_called = (const void*)50; + a.allocate(10, (const void*)0); + assert(A2::allocate_called == (const void*)0); } { typedef std::scoped_allocator_adaptor, A2> A; A a; - A2::allocate_called = false; - assert(a.allocate(10, (const void*)10) == (int*)10); - assert(A2::allocate_called == true); + A2::allocate_called = (const void*)50; + a.allocate(10, (const void*)10); + assert(A2::allocate_called == (const void*)10); } { typedef std::scoped_allocator_adaptor, A2, A3> A; A a; - A2::allocate_called = false; - assert(a.allocate(10, (const void*)20) == (int*)20); - assert(A2::allocate_called == true); + A2::allocate_called = (const void*)50; + a.allocate(10, (const void*)20); + assert(A2::allocate_called == (const void*)20); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } Index: test/std/utilities/allocator.adaptor/allocator.adaptor.members/deallocate.pass.cpp =================================================================== --- test/std/utilities/allocator.adaptor/allocator.adaptor.members/deallocate.pass.cpp +++ test/std/utilities/allocator.adaptor/allocator.adaptor.members/deallocate.pass.cpp @@ -26,20 +26,23 @@ { typedef std::scoped_allocator_adaptor> A; A a; - a.deallocate((int*)10, 20); - assert((A1::deallocate_called == std::pair((int*)10, 20))); + int* p = a.allocate(20); + a.deallocate(p, 20); + assert((A1::deallocate_called == std::pair(p, 20))); } { typedef std::scoped_allocator_adaptor, A2> A; A a; - a.deallocate((int*)10, 20); - assert((A1::deallocate_called == std::pair((int*)10, 20))); + int* p = a.allocate(20); + a.deallocate(p, 20); + assert((A1::deallocate_called == std::pair(p, 20))); } { typedef std::scoped_allocator_adaptor, A2, A3> A; A a; - a.deallocate((int*)10, 20); - assert((A1::deallocate_called == std::pair((int*)10, 20))); + int* p = a.allocate(20); + a.deallocate(p, 20); + assert((A1::deallocate_called == std::pair(p, 20))); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES Index: test/support/allocators.h =================================================================== --- test/support/allocators.h +++ test/support/allocators.h @@ -10,6 +10,7 @@ #ifndef ALLOCATORS_H #define ALLOCATORS_H +#include #include #include @@ -30,7 +31,7 @@ static bool copy_called; static bool move_called; - static bool allocate_called; + static std::size_t allocate_called; static std::pair deallocate_called; A1(const A1& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;} @@ -45,12 +46,13 @@ T* allocate(std::size_t n) { - allocate_called = true; - return (T*)n; + allocate_called = n; + return static_cast(std::malloc(sizeof(T) * n)); } void deallocate(T* p, std::size_t n) { + std::free(p); deallocate_called = std::pair(p, n); } @@ -59,7 +61,7 @@ template bool A1::copy_called = false; template bool A1::move_called = false; -template bool A1::allocate_called = false; +template std::size_t A1::allocate_called = 0; template std::pair A1::deallocate_called; template @@ -94,23 +96,36 @@ static bool copy_called; static bool move_called; - static bool allocate_called; + static const void *allocate_called; A2(const A2& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;} A2(A2&& a) TEST_NOEXCEPT : id_(a.id()) {move_called = true;} A2& operator=(const A2& a) TEST_NOEXCEPT { id_ = a.id(); copy_called = true; return *this;} A2& operator=(A2&& a) TEST_NOEXCEPT { id_ = a.id(); move_called = true; return *this;} + template + A2(const A2& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;} + + T* allocate(std::size_t n) + { + return static_cast(std::malloc(sizeof(T) * n)); + } + T* allocate(std::size_t n, const void* hint) { - allocate_called = true; - return (T*)hint; + allocate_called = hint; + return static_cast(std::malloc(sizeof(T) * n)); + } + + void deallocate(T* p, std::size_t n) + { + std::free(p); } }; template bool A2::copy_called = false; template bool A2::move_called = false; -template bool A2::allocate_called = false; +template const void *A2::allocate_called = (const void*)0; template inline @@ -150,6 +165,19 @@ A3& operator=(const A3& a) TEST_NOEXCEPT { id_ = a.id(); copy_called = true; return *this;} A3& operator=(A3&& a) TEST_NOEXCEPT { id_ = a.id(); move_called = true; return *this;} + template + A3(const A3& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;} + + T* allocate(std::size_t n) + { + return static_cast(std::malloc(sizeof(T) * n)); + } + + void deallocate(T* p, std::size_t n) + { + std::free(p); + } + template void construct(U* p, Args&& ...args) {