diff options
author | 2024-04-12 00:36:46 -0700 | |
---|---|---|
committer | 2024-04-16 19:33:03 +0000 | |
commit | 1f8f41b219eed63ed3532c25cd11efaa692b8478 (patch) | |
tree | 595d6bcd8433b55e592d41538a5efa0ebd7923d4 | |
parent | 5ab729974f972b0a0a3ddbc70f30742a69c6d612 (diff) |
Avoid calling Alloc::{address,construct,destroy}
The std::allocator<T> class deprecates these three methods in C++17 and
removes them in C++20. Replace the address method with the
std::addressof free function. Replace construct and destroy with calls
to std::allocator_traits<allocator_type>::{construct,destroy}, which
calls the method on the allocator if it exists, but otherwise does the
expected thing.
Specifically, the std::allocator_traits functions use placement-new
and an explicit destructor call before C++20, and they use
std::{construct_at,destroy_at} in C++20 and up.
This CL fixes about ~1000 deprecation warnings that happen after
upgrading libc++.
Bug: 311052584
Bug: 333165689
Test: atest art_standalone_libartbase_tests
Test: atest art_standalone_runtime_tests
Test: apply topic:use-prebuilt-libcxx and build Android
Change-Id: Ia981d84882ef15a9c06772d5a9fcbfbc812b8c5c
-rw-r--r-- | libartbase/base/hash_set.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/libartbase/base/hash_set.h b/libartbase/base/hash_set.h index fec9440ebe..91766a75d1 100644 --- a/libartbase/base/hash_set.h +++ b/libartbase/base/hash_set.h @@ -745,7 +745,7 @@ class HashSet { data_ = allocfn_.allocate(num_buckets_); owns_data_ = true; for (size_t i = 0; i < num_buckets_; ++i) { - allocfn_.construct(allocfn_.address(data_[i])); + std::allocator_traits<allocator_type>::construct(allocfn_, std::addressof(data_[i])); emptyfn_.MakeEmpty(data_[i]); } } @@ -753,7 +753,7 @@ class HashSet { void DeallocateStorage() { if (owns_data_) { for (size_t i = 0; i < NumBuckets(); ++i) { - allocfn_.destroy(allocfn_.address(data_[i])); + std::allocator_traits<allocator_type>::destroy(allocfn_, std::addressof(data_[i])); } if (data_ != nullptr) { allocfn_.deallocate(data_, NumBuckets()); @@ -788,7 +788,7 @@ class HashSet { data_[FirstAvailableSlot(IndexForHash(hashfn_(element)))] = std::move(element); } if (owned_data) { - allocfn_.destroy(allocfn_.address(element)); + std::allocator_traits<allocator_type>::destroy(allocfn_, std::addressof(element)); } } if (owned_data) { |