From 28f747d5a4aebdc9afe752a5bd9ddd363645753b Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Fri, 6 Dec 2024 09:16:50 -0500 Subject: [PATCH] Provide only a const version and run required clang-format --- libcxx/test/support/test_allocator.h | 87 +++++++++++++++------------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/libcxx/test/support/test_allocator.h b/libcxx/test/support/test_allocator.h index 49dad642184da31..f8b622d7f95209f 100644 --- a/libcxx/test/support/test_allocator.h +++ b/libcxx/test/support/test_allocator.h @@ -27,45 +27,45 @@ TEST_CONSTEXPR_CXX20 inline typename std::allocator_traits::size_type all } struct test_allocator_statistics { - int time_to_throw = 0; - int throw_after = INT_MAX; + int time_to_throw = 0; + int throw_after = INT_MAX; int count = 0; // the number of active instances int alloc_count = 0; // the number of allocations not deallocating int allocated_size = 0; // the size of allocated elements int construct_count = 0; // the number of times that ::construct was called - int destroy_count = 0; // the number of times that ::destroy was called - int copied = 0; - int moved = 0; - int converted = 0; + int destroy_count = 0; // the number of times that ::destroy was called + 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; + count = 0; + time_to_throw = 0; + alloc_count = 0; allocated_size = 0; construct_count = 0; - destroy_count = 0; - throw_after = INT_MAX; + destroy_count = 0; + throw_after = INT_MAX; clear_ctor_counters(); } TEST_CONSTEXPR_CXX14 void clear_ctor_counters() { - copied = 0; - moved = 0; + copied = 0; + moved = 0; converted = 0; } }; struct test_alloc_base { TEST_CONSTEXPR static const int destructed_value = -1; - TEST_CONSTEXPR static const int moved_value = INT_MAX; + TEST_CONSTEXPR static 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 + int data_ = 0; // participates in equality + int id_ = 0; // unique identifier, doesn't participate in equality test_allocator_statistics* stats_ = nullptr; template @@ -95,7 +95,8 @@ class test_allocator { TEST_CONSTEXPR explicit test_allocator(int data) TEST_NOEXCEPT : data_(data) {} TEST_CONSTEXPR_CXX14 explicit test_allocator(int data, test_allocator_statistics* stats) TEST_NOEXCEPT - : data_(data), stats_(stats) { + : data_(data), + stats_(stats) { if (stats != nullptr) ++stats_->count; } @@ -103,13 +104,17 @@ class test_allocator { TEST_CONSTEXPR explicit test_allocator(int data, int id) TEST_NOEXCEPT : 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) { + : data_(data), + id_(id), + stats_(stats) { if (stats_ != nullptr) ++stats_->count; } TEST_CONSTEXPR_CXX14 test_allocator(const test_allocator& a) TEST_NOEXCEPT - : data_(a.data_), id_(a.id_), stats_(a.stats_) { + : data_(a.data_), + id_(a.id_), + stats_(a.stats_) { assert(a.data_ != test_alloc_base::destructed_value && a.id_ != test_alloc_base::destructed_value && "copying from destroyed allocator"); if (stats_ != nullptr) { @@ -130,7 +135,9 @@ class test_allocator { template TEST_CONSTEXPR_CXX14 test_allocator(const test_allocator& a) TEST_NOEXCEPT - : data_(a.data_), id_(a.id_), stats_(a.stats_) { + : data_(a.data_), + id_(a.id_), + stats_(a.stats_) { if (stats_ != nullptr) { ++stats_->count; ++stats_->converted; @@ -143,7 +150,7 @@ class test_allocator { if (stats_ != nullptr) --stats_->count; data_ = test_alloc_base::destructed_value; - id_ = test_alloc_base::destructed_value; + id_ = test_alloc_base::destructed_value; } TEST_CONSTEXPR pointer address(reference x) const { return &x; } @@ -197,8 +204,8 @@ class test_allocator { template <> class test_allocator { - int data_ = 0; - int id_ = 0; + int data_ = 0; + int id_ = 0; test_allocator_statistics* stats_ = nullptr; template @@ -223,27 +230,30 @@ class test_allocator { 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) - {} + : 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) - {} + : 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_) - {} + : 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_) - {} + : data_(a.data_), + id_(a.id_), + stats_(a.stats_) {} TEST_CONSTEXPR_CXX20 ~test_allocator() TEST_NOEXCEPT { data_ = test_alloc_base::destructed_value; - id_ = test_alloc_base::destructed_value; + id_ = test_alloc_base::destructed_value; } TEST_CONSTEXPR int get_id() const { return id_; } @@ -310,9 +320,9 @@ struct Tag_X { TEST_CONSTEXPR Tag_X(Ctor_Tag, Args&&...) {} // not DefaultConstructible, CopyConstructible or MoveConstructible. - Tag_X() = delete; + Tag_X() = delete; Tag_X(const Tag_X&) = delete; - Tag_X(Tag_X&&) = delete; + Tag_X(Tag_X&&) = delete; // CopyAssignable. TEST_CONSTEXPR_CXX14 Tag_X& operator=(const Tag_X&) { return *this; }; @@ -329,7 +339,7 @@ struct Tag_X { template class TaggingAllocator { public: - using value_type = T; + using value_type = T; TaggingAllocator() = default; template @@ -356,13 +366,13 @@ class TaggingAllocator { template struct limited_alloc_handle { std::size_t outstanding_ = 0; - void* last_alloc_ = nullptr; + void* last_alloc_ = nullptr; template TEST_CONSTEXPR_CXX20 T* allocate(std::size_t N) { if (N + outstanding_ > MaxAllocs) TEST_THROW(std::bad_alloc()); - auto alloc = std::allocator().allocate(N); + auto alloc = std::allocator().allocate(N); last_alloc_ = alloc; outstanding_ += N; return alloc; @@ -467,9 +477,6 @@ class limited_allocator { TEST_CONSTEXPR_CXX20 pointer allocate(size_type n) { return handle_->template allocate(n); } TEST_CONSTEXPR_CXX20 void deallocate(pointer p, size_type n) { handle_->template deallocate(p, n); } TEST_CONSTEXPR size_type max_size() const { return N; } - - // In C++11, constexpr non-static member functions are implicitly const, but this is no longer the case since C++14. - TEST_CONSTEXPR_CXX14 BuffT* getHandle() { return handle_.get(); } TEST_CONSTEXPR const BuffT* getHandle() const { return handle_.get(); } };