| 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 U1, class U2> |
| 18 |
// void polymorphic_allocator<T>::construct(pair<U1, U2>*) |
| 19 |
|
| 20 |
#include <memory_resource> |
| 21 |
#include <cassert> |
| 22 |
#include <tuple> |
| 23 |
#include <type_traits> |
| 24 |
#include <utility> |
| 25 |
#include "uses_alloc_types.h" |
| 26 |
|
| 27 |
int constructed = 0; |
| 28 |
|
| 29 |
template <int> |
| 30 |
struct default_constructible { |
| 31 |
default_constructible() : x(42) { ++constructed; } |
| 32 |
int x = 0; |
| 33 |
}; |
| 34 |
|
| 35 |
int main(int, char**) { |
| 36 |
// pair<default_constructible, default_constructible> |
| 37 |
{ |
| 38 |
typedef default_constructible<0> T; |
| 39 |
typedef std::pair<T, T> P; |
| 40 |
typedef std::pmr::polymorphic_allocator<void> A; |
| 41 |
alignas(P) char buffer[sizeof(P)]; |
| 42 |
P* ptr = reinterpret_cast<P*>(buffer); |
| 43 |
A a; |
| 44 |
constructed = 0; |
| 45 |
a.construct(ptr); |
| 46 |
assert(constructed == 2); |
| 47 |
assert(ptr->first.x == 42); |
| 48 |
assert(ptr->second.x == 42); |
| 49 |
} |
| 50 |
|
| 51 |
// pair<default_constructible<0>, default_constructible<1>> |
| 52 |
{ |
| 53 |
typedef default_constructible<0> T; |
| 54 |
typedef default_constructible<1> U; |
| 55 |
typedef std::pair<T, U> P; |
| 56 |
typedef std::pmr::polymorphic_allocator<void> A; |
| 57 |
alignas(P) char buffer[sizeof(P)]; |
| 58 |
P* ptr = reinterpret_cast<P*>(buffer); |
| 59 |
A a; |
| 60 |
constructed = 0; |
| 61 |
a.construct(ptr); |
| 62 |
assert(constructed == 2); |
| 63 |
assert(ptr->first.x == 42); |
| 64 |
assert(ptr->second.x == 42); |
| 65 |
} |
| 66 |
|
| 67 |
return 0; |
| 68 |
} |