| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// UNSUPPORTED: c++03, c++11, c++14 |
| 10 |
// TODO: Change to XFAIL once https://github.com/llvm/llvm-project/issues/40340 is fixed |
| 11 |
// UNSUPPORTED: availability-pmr-missing |
| 12 |
|
| 13 |
// <memory_resource> |
| 14 |
|
| 15 |
// template <class T> class polymorphic_allocator |
| 16 |
|
| 17 |
// template <class U> |
| 18 |
// void polymorphic_allocator<T>::destroy(U * ptr); |
| 19 |
|
| 20 |
#include <memory_resource> |
| 21 |
#include <cassert> |
| 22 |
#include <new> |
| 23 |
#include <type_traits> |
| 24 |
|
| 25 |
#include "test_macros.h" |
| 26 |
|
| 27 |
int count = 0; |
| 28 |
|
| 29 |
struct destroyable { |
| 30 |
destroyable() { ++count; } |
| 31 |
~destroyable() { --count; } |
| 32 |
}; |
| 33 |
|
| 34 |
int main(int, char**) { |
| 35 |
typedef std::pmr::polymorphic_allocator<double> A; |
| 36 |
{ |
| 37 |
A a; |
| 38 |
ASSERT_SAME_TYPE(decltype(a.destroy((destroyable*)nullptr)), void); |
| 39 |
} |
| 40 |
{ |
| 41 |
alignas(destroyable) char buffer[sizeof(destroyable)]; |
| 42 |
destroyable* ptr = ::new (buffer) destroyable(); |
| 43 |
assert(count == 1); |
| 44 |
A{}.destroy(ptr); |
| 45 |
assert(count == 0); |
| 46 |
} |
| 47 |
|
| 48 |
return 0; |
| 49 |
} |