Index: test/libcxx/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_piecewise_pair.pass.cpp =================================================================== --- test/libcxx/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_piecewise_pair.pass.cpp +++ test/libcxx/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_piecewise_pair.pass.cpp @@ -46,7 +46,7 @@ #include #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/libcxx/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/db_deallocate.pass.cpp =================================================================== --- test/libcxx/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/db_deallocate.pass.cpp +++ test/libcxx/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/db_deallocate.pass.cpp @@ -23,7 +23,7 @@ #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp =================================================================== --- test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp +++ test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp @@ -23,7 +23,7 @@ #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.ctor/default.pass.cpp =================================================================== --- test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.ctor/default.pass.cpp +++ test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.ctor/default.pass.cpp @@ -20,7 +20,7 @@ #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.ctor/memory_resource_convert.pass.cpp =================================================================== --- test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.ctor/memory_resource_convert.pass.cpp +++ test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.ctor/memory_resource_convert.pass.cpp @@ -19,7 +19,7 @@ #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.eq/equal.pass.cpp =================================================================== --- test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.eq/equal.pass.cpp +++ test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.eq/equal.pass.cpp @@ -23,7 +23,7 @@ #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.eq/not_equal.pass.cpp =================================================================== --- test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.eq/not_equal.pass.cpp +++ test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.eq/not_equal.pass.cpp @@ -23,7 +23,7 @@ #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/allocate.pass.cpp =================================================================== --- test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/allocate.pass.cpp +++ test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/allocate.pass.cpp @@ -24,7 +24,7 @@ #include #include "test_macros.h" -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_pair_const_lvalue_pair.pass.cpp =================================================================== --- test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_pair_const_lvalue_pair.pass.cpp +++ test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_pair_const_lvalue_pair.pass.cpp @@ -25,7 +25,7 @@ #include #include "test_macros.h" -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" #include "uses_alloc_types.hpp" #include "controlled_allocators.hpp" #include "test_allocator.h" Index: test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_pair_rvalue.pass.cpp =================================================================== --- test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_pair_rvalue.pass.cpp +++ test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_pair_rvalue.pass.cpp @@ -25,7 +25,7 @@ #include #include "test_macros.h" -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" #include "uses_alloc_types.hpp" #include "controlled_allocators.hpp" #include "test_allocator.h" Index: test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_pair_values.pass.cpp =================================================================== --- test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_pair_values.pass.cpp +++ test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_pair_values.pass.cpp @@ -25,7 +25,7 @@ #include #include "test_macros.h" -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" #include "uses_alloc_types.hpp" #include "controlled_allocators.hpp" #include "test_allocator.h" Index: test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_piecewise_pair.pass.cpp =================================================================== --- test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_piecewise_pair.pass.cpp +++ test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_piecewise_pair.pass.cpp @@ -26,7 +26,7 @@ #include #include "test_macros.h" -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" #include "uses_alloc_types.hpp" #include "controlled_allocators.hpp" #include "test_allocator.h" Index: test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_types.pass.cpp =================================================================== --- test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_types.pass.cpp +++ test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_types.pass.cpp @@ -23,7 +23,7 @@ #include #include "test_macros.h" -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" #include "uses_alloc_types.hpp" #include "controlled_allocators.hpp" #include "test_allocator.h" Index: test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/deallocate.pass.cpp =================================================================== --- test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/deallocate.pass.cpp +++ test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/deallocate.pass.cpp @@ -20,7 +20,7 @@ #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.ctor/alloc_copy.pass.cpp =================================================================== --- test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.ctor/alloc_copy.pass.cpp +++ test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.ctor/alloc_copy.pass.cpp @@ -18,7 +18,7 @@ #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.ctor/alloc_move.pass.cpp =================================================================== --- test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.ctor/alloc_move.pass.cpp +++ test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.ctor/alloc_move.pass.cpp @@ -18,7 +18,7 @@ #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.ctor/default.pass.cpp =================================================================== --- test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.ctor/default.pass.cpp +++ test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.ctor/default.pass.cpp @@ -20,7 +20,7 @@ #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/do_allocate_and_deallocate.pass.cpp =================================================================== --- test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/do_allocate_and_deallocate.pass.cpp +++ test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/do_allocate_and_deallocate.pass.cpp @@ -24,7 +24,7 @@ #include #include "test_macros.h" -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/do_is_equal.pass.cpp =================================================================== --- test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/do_is_equal.pass.cpp +++ test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/do_is_equal.pass.cpp @@ -19,7 +19,7 @@ #include #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" using std::size_t; namespace ex = std::experimental::pmr; Index: test/std/experimental/memory/memory.resource.global/default_resource.pass.cpp =================================================================== --- test/std/experimental/memory/memory.resource.global/default_resource.pass.cpp +++ test/std/experimental/memory/memory.resource.global/default_resource.pass.cpp @@ -33,7 +33,7 @@ #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" using namespace std::experimental::pmr; Index: test/std/experimental/memory/memory.resource/memory.resource.eq/equal.pass.cpp =================================================================== --- test/std/experimental/memory/memory.resource/memory.resource.eq/equal.pass.cpp +++ test/std/experimental/memory/memory.resource/memory.resource.eq/equal.pass.cpp @@ -18,7 +18,7 @@ #include #include "test_macros.h" -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/std/experimental/memory/memory.resource/memory.resource.eq/not_equal.pass.cpp =================================================================== --- test/std/experimental/memory/memory.resource/memory.resource.eq/not_equal.pass.cpp +++ test/std/experimental/memory/memory.resource/memory.resource.eq/not_equal.pass.cpp @@ -17,7 +17,7 @@ #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" namespace ex = std::experimental::pmr; Index: test/std/experimental/memory/memory.resource/memory.resource.public/allocate.pass.cpp =================================================================== --- test/std/experimental/memory/memory.resource/memory.resource.public/allocate.pass.cpp +++ test/std/experimental/memory/memory.resource/memory.resource.public/allocate.pass.cpp @@ -28,7 +28,7 @@ #include #include "test_macros.h" -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" using std::experimental::pmr::memory_resource; Index: test/std/experimental/memory/memory.resource/memory.resource.public/deallocate.pass.cpp =================================================================== --- test/std/experimental/memory/memory.resource/memory.resource.public/deallocate.pass.cpp +++ test/std/experimental/memory/memory.resource/memory.resource.public/deallocate.pass.cpp @@ -27,7 +27,7 @@ #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" using std::experimental::pmr::memory_resource; Index: test/std/experimental/memory/memory.resource/memory.resource.public/dtor.pass.cpp =================================================================== --- test/std/experimental/memory/memory.resource/memory.resource.public/dtor.pass.cpp +++ test/std/experimental/memory/memory.resource/memory.resource.public/dtor.pass.cpp @@ -23,7 +23,7 @@ #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" using std::experimental::pmr::memory_resource; Index: test/std/experimental/memory/memory.resource/memory.resource.public/is_equal.pass.cpp =================================================================== --- test/std/experimental/memory/memory.resource/memory.resource.public/is_equal.pass.cpp +++ test/std/experimental/memory/memory.resource/memory.resource.public/is_equal.pass.cpp @@ -25,7 +25,7 @@ #include #include #include -#include "test_memory_resource.hpp" +#include "test_experimental_memory_resource.hpp" using std::experimental::pmr::memory_resource; Index: test/support/test_experimental_memory_resource.hpp =================================================================== --- /dev/null +++ test/support/test_experimental_memory_resource.hpp @@ -0,0 +1,171 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef SUPPORT_TEST_EXPERIMENTAL_MEMORY_RESOURCE_HPP +#define SUPPORT_TEST_EXPERIMENTAL_MEMORY_RESOURCE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "test_macros.h" +#include "controlled_allocators.hpp" +#include "uses_alloc_types.hpp" + +// FIXME: This is a hack to allow uses_allocator_types.hpp to work with +// erased_type. However we can't define that behavior directly in the header +// because it can't include +template <> +struct TransformErasedTypeAlloc { + using type = std::experimental::pmr::memory_resource*; +}; + +template +class TestResourceImp : public std::experimental::pmr::memory_resource +{ +public: + static int resource_alive; + static int resource_constructed; + static int resource_destructed; + + static void resetStatics() { + assert(resource_alive == 0); + resource_alive = 0; + resource_constructed = 0; + resource_destructed = 0; + } + + using memory_resource = std::experimental::pmr::memory_resource; + using Provider = ProviderT; + + int value; + + explicit TestResourceImp(int val = 0) : value(val) { + ++resource_alive; + ++resource_constructed; + } + + ~TestResourceImp() noexcept { + --resource_alive; + ++resource_destructed; + } + + void reset() { C.reset(); P.reset(); } + AllocController& getController() { return C; } + + bool checkAlloc(void* p, std::size_t s, std::size_t a) const + { return C.checkAlloc(p, s, a); } + + bool checkDealloc(void* p, std::size_t s, std::size_t a) const + { return C.checkDealloc(p, s, a); } + + bool checkIsEqualCalledEq(int n) const { return C.checkIsEqualCalledEq(n); } + +protected: + virtual void * do_allocate(std::size_t s, std::size_t a) { + if (C.throw_on_alloc) { +#ifndef TEST_HAS_NO_EXCEPTIONS + throw TestException{}; +#else + assert(false); +#endif + } + void* ret = P.allocate(s, a); + C.countAlloc(ret, s, a); + return ret; + } + + virtual void do_deallocate(void * p, std::size_t s, std::size_t a) { + C.countDealloc(p, s, a); + P.deallocate(p, s, a); + } + + virtual bool do_is_equal(memory_resource const & other) const noexcept { + C.countIsEqual(); + TestResourceImp const * o = dynamic_cast(&other); + return o && o->value == value; + } +private: + mutable AllocController C; + mutable Provider P; + DISALLOW_COPY(TestResourceImp); +}; + +template +int TestResourceImp::resource_alive = 0; + +template +int TestResourceImp::resource_constructed = 0; + +template +int TestResourceImp::resource_destructed = 0; + + +struct NullProvider { + NullProvider() {} + void* allocate(size_t, size_t) { return nullptr; } + void deallocate(void*, size_t, size_t) {} + void reset() {} +private: + DISALLOW_COPY(NullProvider); +}; + +struct NewDeleteProvider { + NewDeleteProvider() {} + void* allocate(size_t s, size_t) { return ::operator new(s); } + void deallocate(void* p, size_t, size_t) { ::operator delete(p); } + void reset() {} +private: + DISALLOW_COPY(NewDeleteProvider); +}; + +template // 10 pages worth of memory. +struct BufferProvider { + char buffer[Size]; + void* next = &buffer; + size_t space = Size; + + BufferProvider() {} + + void* allocate(size_t s, size_t a) { + void* ret = std::align(s, a, next, space); + if (ret == nullptr) { +#ifndef TEST_HAS_NO_EXCEPTIONS + throw std::bad_alloc(); +#else + assert(false); +#endif + } + + return ret; + } + + void deallocate(void*, size_t, size_t) {} + + void reset() { + next = &buffer; + space = Size; + } +private: + DISALLOW_COPY(BufferProvider); +}; + +using NullResource = TestResourceImp; +using NewDeleteResource = TestResourceImp; +using TestResource = TestResourceImp, 0>; +using TestResource1 = TestResourceImp, 1>; +using TestResource2 = TestResourceImp, 2>; + + +#endif /* SUPPORT_TEST_EXPERIMENTAL_MEMORY_RESOURCE_HPP */ Index: test/support/test_memory_resource.hpp =================================================================== --- test/support/test_memory_resource.hpp +++ /dev/null @@ -1,171 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef SUPPORT_TEST_MEMORY_RESOURCE_HPP -#define SUPPORT_TEST_MEMORY_RESOURCE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "test_macros.h" -#include "controlled_allocators.hpp" -#include "uses_alloc_types.hpp" - -// FIXME: This is a hack to allow uses_allocator_types.hpp to work with -// erased_type. However we can't define that behavior directly in the header -// because it can't include -template <> -struct TransformErasedTypeAlloc { - using type = std::experimental::pmr::memory_resource*; -}; - -template -class TestResourceImp : public std::experimental::pmr::memory_resource -{ -public: - static int resource_alive; - static int resource_constructed; - static int resource_destructed; - - static void resetStatics() { - assert(resource_alive == 0); - resource_alive = 0; - resource_constructed = 0; - resource_destructed = 0; - } - - using memory_resource = std::experimental::pmr::memory_resource; - using Provider = ProviderT; - - int value; - - explicit TestResourceImp(int val = 0) : value(val) { - ++resource_alive; - ++resource_constructed; - } - - ~TestResourceImp() noexcept { - --resource_alive; - ++resource_destructed; - } - - void reset() { C.reset(); P.reset(); } - AllocController& getController() { return C; } - - bool checkAlloc(void* p, std::size_t s, std::size_t a) const - { return C.checkAlloc(p, s, a); } - - bool checkDealloc(void* p, std::size_t s, std::size_t a) const - { return C.checkDealloc(p, s, a); } - - bool checkIsEqualCalledEq(int n) const { return C.checkIsEqualCalledEq(n); } - -protected: - virtual void * do_allocate(std::size_t s, std::size_t a) { - if (C.throw_on_alloc) { -#ifndef TEST_HAS_NO_EXCEPTIONS - throw TestException{}; -#else - assert(false); -#endif - } - void* ret = P.allocate(s, a); - C.countAlloc(ret, s, a); - return ret; - } - - virtual void do_deallocate(void * p, std::size_t s, std::size_t a) { - C.countDealloc(p, s, a); - P.deallocate(p, s, a); - } - - virtual bool do_is_equal(memory_resource const & other) const noexcept { - C.countIsEqual(); - TestResourceImp const * o = dynamic_cast(&other); - return o && o->value == value; - } -private: - mutable AllocController C; - mutable Provider P; - DISALLOW_COPY(TestResourceImp); -}; - -template -int TestResourceImp::resource_alive = 0; - -template -int TestResourceImp::resource_constructed = 0; - -template -int TestResourceImp::resource_destructed = 0; - - -struct NullProvider { - NullProvider() {} - void* allocate(size_t, size_t) { return nullptr; } - void deallocate(void*, size_t, size_t) {} - void reset() {} -private: - DISALLOW_COPY(NullProvider); -}; - -struct NewDeleteProvider { - NewDeleteProvider() {} - void* allocate(size_t s, size_t) { return ::operator new(s); } - void deallocate(void* p, size_t, size_t) { ::operator delete(p); } - void reset() {} -private: - DISALLOW_COPY(NewDeleteProvider); -}; - -template // 10 pages worth of memory. -struct BufferProvider { - char buffer[Size]; - void* next = &buffer; - size_t space = Size; - - BufferProvider() {} - - void* allocate(size_t s, size_t a) { - void* ret = std::align(s, a, next, space); - if (ret == nullptr) { -#ifndef TEST_HAS_NO_EXCEPTIONS - throw std::bad_alloc(); -#else - assert(false); -#endif - } - - return ret; - } - - void deallocate(void*, size_t, size_t) {} - - void reset() { - next = &buffer; - space = Size; - } -private: - DISALLOW_COPY(BufferProvider); -}; - -using NullResource = TestResourceImp; -using NewDeleteResource = TestResourceImp; -using TestResource = TestResourceImp, 0>; -using TestResource1 = TestResourceImp, 1>; -using TestResource2 = TestResourceImp, 2>; - - -#endif /* SUPPORT_TEST_MEMORY_RESOURCE_HPP */ Index: test/support/uses_alloc_types.hpp =================================================================== --- test/support/uses_alloc_types.hpp +++ test/support/uses_alloc_types.hpp @@ -143,7 +143,7 @@ // polymorphic allocators. However we don't want to include // in this header. Therefore in order // to inject this behavior later we use a trait. -// See test_memory_resource.hpp for more info. +// See test_experimental_memory_resource.hpp for more info. template struct TransformErasedTypeAlloc { using type = Alloc;