[libcxx-commits] [libcxx] 2979070 - [libc++] Simplify non_default_alloc
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 10 15:04:19 PST 2023
Author: Louis Dionne
Date: 2023-02-10T15:02:05-08:00
New Revision: 2979070f1b3a9c2150a088a16423d84c6a361ca9
URL: https://github.com/llvm/llvm-project/commit/2979070f1b3a9c2150a088a16423d84c6a361ca9
DIFF: https://github.com/llvm/llvm-project/commit/2979070f1b3a9c2150a088a16423d84c6a361ca9.diff
LOG: [libc++] Simplify non_default_alloc
Also, since it is only used in two tests that are C++11/C++14 tests only,
I don't think it is worth keeping around in test_allocator.h.
Added:
Modified:
libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp
libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp
libcxx/test/support/test_allocator.h
Removed:
################################################################################
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 <class T>
+struct non_default_test_allocator : test_allocator<T> {
+ non_default_test_allocator() = delete;
+ using test_allocator<T>::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 <class T>
+struct non_default_test_allocator : test_allocator<T> {
+ non_default_test_allocator() = delete;
+ using test_allocator<T>::test_allocator;
+};
+
class DummyClass {};
template <class FuncType, class AllocType>
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 T>
-class non_default_test_allocator {
- int data_ = 0;
- test_allocator_statistics* stats_ = nullptr;
-
- template <class U>
- friend class non_default_test_allocator;
-
-public:
- typedef unsigned size_type;
- typedef int
diff erence_type;
- typedef T value_type;
- typedef value_type* pointer;
- typedef const value_type* const_pointer;
- typedef typename std::add_lvalue_reference<value_type>::type reference;
- typedef typename std::add_lvalue_reference<const value_type>::type const_reference;
-
- template <class U>
- struct rebind {
- typedef non_default_test_allocator<U> 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 <class U>
- TEST_CONSTEXPR_CXX14 non_default_test_allocator(const non_default_test_allocator<U>& 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<value_type>().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<value_type>().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<void> {
int data_ = 0;
More information about the libcxx-commits
mailing list