Skip to content

Commit 479e0e4

Browse files
committed
Provide only a const version and run required clang-format
1 parent 9605ae0 commit 479e0e4

File tree

1 file changed

+47
-40
lines changed

1 file changed

+47
-40
lines changed

libcxx/test/support/test_allocator.h

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,45 @@ TEST_CONSTEXPR_CXX20 inline typename std::allocator_traits<Alloc>::size_type all
2727
}
2828

2929
struct test_allocator_statistics {
30-
int time_to_throw = 0;
31-
int throw_after = INT_MAX;
30+
int time_to_throw = 0;
31+
int throw_after = INT_MAX;
3232
int count = 0; // the number of active instances
3333
int alloc_count = 0; // the number of allocations not deallocating
3434
int allocated_size = 0; // the size of allocated elements
3535
int construct_count = 0; // the number of times that ::construct was called
36-
int destroy_count = 0; // the number of times that ::destroy was called
37-
int copied = 0;
38-
int moved = 0;
39-
int converted = 0;
36+
int destroy_count = 0; // the number of times that ::destroy was called
37+
int copied = 0;
38+
int moved = 0;
39+
int converted = 0;
4040

4141
TEST_CONSTEXPR_CXX14 void clear() {
4242
assert(count == 0 && "clearing leaking allocator data?");
43-
count = 0;
44-
time_to_throw = 0;
45-
alloc_count = 0;
43+
count = 0;
44+
time_to_throw = 0;
45+
alloc_count = 0;
4646
allocated_size = 0;
4747
construct_count = 0;
48-
destroy_count = 0;
49-
throw_after = INT_MAX;
48+
destroy_count = 0;
49+
throw_after = INT_MAX;
5050
clear_ctor_counters();
5151
}
5252

5353
TEST_CONSTEXPR_CXX14 void clear_ctor_counters() {
54-
copied = 0;
55-
moved = 0;
54+
copied = 0;
55+
moved = 0;
5656
converted = 0;
5757
}
5858
};
5959

6060
struct test_alloc_base {
6161
TEST_CONSTEXPR static const int destructed_value = -1;
62-
TEST_CONSTEXPR static const int moved_value = INT_MAX;
62+
TEST_CONSTEXPR static const int moved_value = INT_MAX;
6363
};
6464

6565
template <class T>
6666
class test_allocator {
67-
int data_ = 0; // participates in equality
68-
int id_ = 0; // unique identifier, doesn't participate in equality
67+
int data_ = 0; // participates in equality
68+
int id_ = 0; // unique identifier, doesn't participate in equality
6969
test_allocator_statistics* stats_ = nullptr;
7070

7171
template <class U>
@@ -95,21 +95,26 @@ class test_allocator {
9595
TEST_CONSTEXPR explicit test_allocator(int data) TEST_NOEXCEPT : data_(data) {}
9696

9797
TEST_CONSTEXPR_CXX14 explicit test_allocator(int data, test_allocator_statistics* stats) TEST_NOEXCEPT
98-
: data_(data), stats_(stats) {
98+
: data_(data),
99+
stats_(stats) {
99100
if (stats != nullptr)
100101
++stats_->count;
101102
}
102103

103104
TEST_CONSTEXPR explicit test_allocator(int data, int id) TEST_NOEXCEPT : data_(data), id_(id) {}
104105

105106
TEST_CONSTEXPR_CXX14 explicit test_allocator(int data, int id, test_allocator_statistics* stats) TEST_NOEXCEPT
106-
: data_(data), id_(id), stats_(stats) {
107+
: data_(data),
108+
id_(id),
109+
stats_(stats) {
107110
if (stats_ != nullptr)
108111
++stats_->count;
109112
}
110113

111114
TEST_CONSTEXPR_CXX14 test_allocator(const test_allocator& a) TEST_NOEXCEPT
112-
: data_(a.data_), id_(a.id_), stats_(a.stats_) {
115+
: data_(a.data_),
116+
id_(a.id_),
117+
stats_(a.stats_) {
113118
assert(a.data_ != test_alloc_base::destructed_value && a.id_ != test_alloc_base::destructed_value &&
114119
"copying from destroyed allocator");
115120
if (stats_ != nullptr) {
@@ -130,7 +135,9 @@ class test_allocator {
130135

131136
template <class U>
132137
TEST_CONSTEXPR_CXX14 test_allocator(const test_allocator<U>& a) TEST_NOEXCEPT
133-
: data_(a.data_), id_(a.id_), stats_(a.stats_) {
138+
: data_(a.data_),
139+
id_(a.id_),
140+
stats_(a.stats_) {
134141
if (stats_ != nullptr) {
135142
++stats_->count;
136143
++stats_->converted;
@@ -143,7 +150,7 @@ class test_allocator {
143150
if (stats_ != nullptr)
144151
--stats_->count;
145152
data_ = test_alloc_base::destructed_value;
146-
id_ = test_alloc_base::destructed_value;
153+
id_ = test_alloc_base::destructed_value;
147154
}
148155

149156
TEST_CONSTEXPR pointer address(reference x) const { return &x; }
@@ -197,8 +204,8 @@ class test_allocator {
197204

198205
template <>
199206
class test_allocator<void> {
200-
int data_ = 0;
201-
int id_ = 0;
207+
int data_ = 0;
208+
int id_ = 0;
202209
test_allocator_statistics* stats_ = nullptr;
203210

204211
template <class U>
@@ -223,27 +230,30 @@ class test_allocator<void> {
223230
TEST_CONSTEXPR explicit test_allocator(int data) TEST_NOEXCEPT : data_(data) {}
224231

225232
TEST_CONSTEXPR explicit test_allocator(int data, test_allocator_statistics* stats) TEST_NOEXCEPT
226-
: data_(data), stats_(stats)
227-
{}
233+
: data_(data),
234+
stats_(stats) {}
228235

229236
TEST_CONSTEXPR explicit test_allocator(int data, int id) : data_(data), id_(id) {}
230237

231238
TEST_CONSTEXPR_CXX14 explicit test_allocator(int data, int id, test_allocator_statistics* stats) TEST_NOEXCEPT
232-
: data_(data), id_(id), stats_(stats)
233-
{}
239+
: data_(data),
240+
id_(id),
241+
stats_(stats) {}
234242

235243
TEST_CONSTEXPR_CXX14 explicit test_allocator(const test_allocator& a) TEST_NOEXCEPT
236-
: data_(a.data_), id_(a.id_), stats_(a.stats_)
237-
{}
244+
: data_(a.data_),
245+
id_(a.id_),
246+
stats_(a.stats_) {}
238247

239248
template <class U>
240249
TEST_CONSTEXPR_CXX14 test_allocator(const test_allocator<U>& a) TEST_NOEXCEPT
241-
: data_(a.data_), id_(a.id_), stats_(a.stats_)
242-
{}
250+
: data_(a.data_),
251+
id_(a.id_),
252+
stats_(a.stats_) {}
243253

244254
TEST_CONSTEXPR_CXX20 ~test_allocator() TEST_NOEXCEPT {
245255
data_ = test_alloc_base::destructed_value;
246-
id_ = test_alloc_base::destructed_value;
256+
id_ = test_alloc_base::destructed_value;
247257
}
248258

249259
TEST_CONSTEXPR int get_id() const { return id_; }
@@ -310,9 +320,9 @@ struct Tag_X {
310320
TEST_CONSTEXPR Tag_X(Ctor_Tag, Args&&...) {}
311321

312322
// not DefaultConstructible, CopyConstructible or MoveConstructible.
313-
Tag_X() = delete;
323+
Tag_X() = delete;
314324
Tag_X(const Tag_X&) = delete;
315-
Tag_X(Tag_X&&) = delete;
325+
Tag_X(Tag_X&&) = delete;
316326

317327
// CopyAssignable.
318328
TEST_CONSTEXPR_CXX14 Tag_X& operator=(const Tag_X&) { return *this; };
@@ -329,7 +339,7 @@ struct Tag_X {
329339
template <typename T>
330340
class TaggingAllocator {
331341
public:
332-
using value_type = T;
342+
using value_type = T;
333343
TaggingAllocator() = default;
334344

335345
template <typename U>
@@ -356,13 +366,13 @@ class TaggingAllocator {
356366
template <std::size_t MaxAllocs>
357367
struct limited_alloc_handle {
358368
std::size_t outstanding_ = 0;
359-
void* last_alloc_ = nullptr;
369+
void* last_alloc_ = nullptr;
360370

361371
template <class T>
362372
TEST_CONSTEXPR_CXX20 T* allocate(std::size_t N) {
363373
if (N + outstanding_ > MaxAllocs)
364374
TEST_THROW(std::bad_alloc());
365-
auto alloc = std::allocator<T>().allocate(N);
375+
auto alloc = std::allocator<T>().allocate(N);
366376
last_alloc_ = alloc;
367377
outstanding_ += N;
368378
return alloc;
@@ -467,9 +477,6 @@ class limited_allocator {
467477
TEST_CONSTEXPR_CXX20 pointer allocate(size_type n) { return handle_->template allocate<T>(n); }
468478
TEST_CONSTEXPR_CXX20 void deallocate(pointer p, size_type n) { handle_->template deallocate<T>(p, n); }
469479
TEST_CONSTEXPR size_type max_size() const { return N; }
470-
471-
// In C++11, constexpr non-static member functions are implicitly const, but this is no longer the case since C++14.
472-
TEST_CONSTEXPR_CXX14 BuffT* getHandle() { return handle_.get(); }
473480
TEST_CONSTEXPR const BuffT* getHandle() const { return handle_.get(); }
474481
};
475482

0 commit comments

Comments
 (0)