Skip to content

Commit f1d66e6

Browse files
Use TEST_MAYBE_UNUSED, separately count allocations and deallocations
1 parent bc01ebc commit f1d66e6

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
#include "test_macros.h"
2020

21-
static std::ptrdiff_t allocated_;
21+
static std::size_t allocated_;
22+
static std::size_t deallocated_;
2223

2324
template <class T, class Sz>
2425
struct test_alloc {
@@ -41,12 +42,12 @@ struct test_alloc {
4142
TEST_CONSTEXPR test_alloc(const test_alloc<U, Sz>&) TEST_NOEXCEPT {}
4243

4344
pointer allocate(size_type n, const void* = nullptr) {
44-
allocated_ += static_cast<std::ptrdiff_t>(n);
45+
allocated_ += static_cast<std::size_t>(n);
4546
return std::allocator<value_type>().allocate(static_cast<std::size_t>(n));
4647
}
4748

4849
void deallocate(pointer p, size_type s) {
49-
allocated_ -= static_cast<std::ptrdiff_t>(s);
50+
deallocated_ += static_cast<std::size_t>(s);
5051
std::allocator<value_type>().deallocate(p, static_cast<std::size_t>(s));
5152
}
5253

@@ -65,13 +66,11 @@ struct test_alloc {
6566

6667
template <class Sz>
6768
void test() {
68-
using Str = std::basic_string<char, std::char_traits<char>, test_alloc<char, Sz> >;
6969
for (int i = 1; i < 1000; ++i) {
7070
{
71-
Str s(i, 't');
72-
(void)s;
71+
TEST_MAYBE_UNUSED std::basic_string<char, std::char_traits<char>, test_alloc<char, Sz> > s(i, 't');
7372
}
74-
assert(allocated_ == 0);
73+
assert(allocated_ == deallocated_);
7574
}
7675
}
7776

0 commit comments

Comments
 (0)