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 index 1c546477b5287..733a057ade196 100644 --- 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 @@ -33,6 +33,12 @@ struct LValueCallable { }; #endif +template +struct non_default_test_allocator : test_allocator { + non_default_test_allocator() = delete; + using test_allocator::test_allocator; +}; + test_allocator_statistics alloc_stats; class DummyClass {}; diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp index 4537e6d760245..00b367522e688 100644 --- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp @@ -22,6 +22,12 @@ #include "count_new.h" #include "../function_types.h" +template +struct non_default_test_allocator : test_allocator { + non_default_test_allocator() = delete; + using test_allocator::test_allocator; +}; + class DummyClass {}; template diff --git a/libcxx/test/support/test_allocator.h b/libcxx/test/support/test_allocator.h index 3b9676ee17526..b2c1ed6323eee 100644 --- a/libcxx/test/support/test_allocator.h +++ b/libcxx/test/support/test_allocator.h @@ -181,88 +181,6 @@ class test_allocator { TEST_CONSTEXPR int get_id() const { return id_; } }; -template -class non_default_test_allocator { - int data_ = 0; - test_allocator_statistics* stats_ = nullptr; - - 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; - }; - - TEST_CONSTEXPR_CXX14 - explicit non_default_test_allocator(int i, test_allocator_statistics* stats = nullptr) TEST_NOEXCEPT - : data_(i), stats_(stats) { - if (stats_ != nullptr) { - ++stats_->count; - } - } - - TEST_CONSTEXPR_CXX14 - non_default_test_allocator(const non_default_test_allocator& a) TEST_NOEXCEPT : data_(a.data_), stats_(a.stats_) { - if (stats_ != nullptr) - ++stats_->count; - } - - template - TEST_CONSTEXPR_CXX14 non_default_test_allocator(const non_default_test_allocator& a) TEST_NOEXCEPT - : data_(a.data_), stats_(a.stats_) { - if (stats_ != nullptr) - ++stats_->count; - } - - TEST_CONSTEXPR_CXX20 ~non_default_test_allocator() TEST_NOEXCEPT { - assert(data_ != test_alloc_base::destructed_value); - if (stats_ != nullptr) - --stats_->count; - data_ = test_alloc_base::destructed_value; - } - - TEST_CONSTEXPR pointer address(reference x) const { return &x; } - TEST_CONSTEXPR const_pointer address(const_reference x) const { return &x; } - - TEST_CONSTEXPR_CXX20 pointer allocate(size_type n, const void* = nullptr) { - assert(data_ != test_alloc_base::destructed_value); - if (stats_ != nullptr) { - if (stats_->time_to_throw >= stats_->throw_after) - TEST_THROW(std::bad_alloc()); - ++stats_->time_to_throw; - ++stats_->alloc_count; - } - return std::allocator().allocate(n); - } - - TEST_CONSTEXPR_CXX20 void deallocate(pointer p, size_type n) { - assert(data_ != test_alloc_base::destructed_value); - if (stats_ != nullptr) - --stats_->alloc_count; - std::allocator().deallocate(p, n); - } - - TEST_CONSTEXPR size_type max_size() const TEST_NOEXCEPT { return UINT_MAX / sizeof(T); } - - TEST_CONSTEXPR friend bool operator==(const non_default_test_allocator& x, const non_default_test_allocator& y) { - return x.data_ == y.data_; - } - - TEST_CONSTEXPR friend bool operator!=(const non_default_test_allocator& x, const non_default_test_allocator& y) { - return !(x == y); - } -}; - template <> class test_allocator { int data_ = 0;