Skip to content

Commit f71ea0e

Browse files
[libc++][test] Augment test_alloc in deallocate_size.pass.cpp (#113638)
Making it meet the requirements for allocator since C++11. Fixes #113609. This PR doesn't make it meet the C++03 allocator requirements, because that would make the type too verbose and libc++ has backported many C++11 features to the C++03 mode. Drive-by: Removes the `TEST_CONSTEXPR_CXX14` on `allocate`/`dealocate` which is never in effect (and causes IFNDR-ness before C++23), since these functions modify the namespace-scoped variable `allocated_`.
1 parent d90a0d1 commit f71ea0e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,32 @@ struct test_alloc {
3434
typedef test_alloc<U, Sz> other;
3535
};
3636

37-
TEST_CONSTEXPR_CXX14 pointer allocate(size_type n, const void* = nullptr) {
37+
TEST_CONSTEXPR test_alloc() TEST_NOEXCEPT {}
38+
39+
template <class U>
40+
TEST_CONSTEXPR test_alloc(const test_alloc<U, Sz>&) TEST_NOEXCEPT {}
41+
42+
pointer allocate(size_type n, const void* = nullptr) {
3843
allocated_ += n;
3944
return std::allocator<value_type>().allocate(n);
4045
}
4146

42-
TEST_CONSTEXPR_CXX14 void deallocate(pointer p, size_type s) {
47+
void deallocate(pointer p, size_type s) {
4348
allocated_ -= s;
4449
std::allocator<value_type>().deallocate(p, s);
4550
}
51+
52+
template <class U>
53+
friend TEST_CONSTEXPR bool operator==(const test_alloc&, const test_alloc<U, Sz>&) TEST_NOEXCEPT {
54+
return true;
55+
}
56+
57+
#if TEST_STD_VER < 20
58+
template <class U>
59+
friend TEST_CONSTEXPR bool operator!=(const test_alloc&, const test_alloc<U, Sz>&) TEST_NOEXCEPT {
60+
return false;
61+
}
62+
#endif
4663
};
4764

4865
template <class Sz>

0 commit comments

Comments
 (0)