| 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 |
// test_memory_resource requires RTTI for dynamic_cast |
| 14 |
// UNSUPPORTED: no-rtti |
| 15 |
|
| 16 |
// <memory_resource> |
| 17 |
|
| 18 |
// template <class T> class polymorphic_allocator; |
| 19 |
|
| 20 |
// template <class T> |
| 21 |
// bool operator!=( |
| 22 |
// polymorphic_allocator<T> const & |
| 23 |
// , polymorphic_allocator<T> const &) noexcept |
| 24 |
|
| 25 |
#include <memory_resource> |
| 26 |
#include <cassert> |
| 27 |
#include <type_traits> |
| 28 |
|
| 29 |
#include "test_macros.h" |
| 30 |
#include "test_std_memory_resource.h" |
| 31 |
|
| 32 |
int main(int, char**) { |
| 33 |
typedef std::pmr::polymorphic_allocator<void> A1; |
| 34 |
typedef std::pmr::polymorphic_allocator<int> A2; |
| 35 |
// check return types |
| 36 |
{ |
| 37 |
A1 const a1; |
| 38 |
A2 const a2; |
| 39 |
ASSERT_SAME_TYPE(decltype(a1 != a2), bool); |
| 40 |
ASSERT_NOEXCEPT(a1 != a2); |
| 41 |
} |
| 42 |
// not equal same type (different resource) |
| 43 |
{ |
| 44 |
TestResource d1(1); |
| 45 |
TestResource d2(2); |
| 46 |
A1 const a1(&d1); |
| 47 |
A1 const a2(&d2); |
| 48 |
|
| 49 |
assert(a1 != a2); |
| 50 |
assert(d1.checkIsEqualCalledEq(1)); |
| 51 |
assert(d2.checkIsEqualCalledEq(0)); |
| 52 |
|
| 53 |
d1.reset(); |
| 54 |
|
| 55 |
assert(a2 != a1); |
| 56 |
assert(d1.checkIsEqualCalledEq(0)); |
| 57 |
assert(d2.checkIsEqualCalledEq(1)); |
| 58 |
} |
| 59 |
// equal same type (same resource) |
| 60 |
{ |
| 61 |
TestResource d1; |
| 62 |
A1 const a1(&d1); |
| 63 |
A1 const a2(&d1); |
| 64 |
|
| 65 |
assert(!(a1 != a2)); |
| 66 |
assert(d1.checkIsEqualCalledEq(0)); |
| 67 |
|
| 68 |
assert(!(a2 != a1)); |
| 69 |
assert(d1.checkIsEqualCalledEq(0)); |
| 70 |
} |
| 71 |
// equal same type |
| 72 |
{ |
| 73 |
TestResource d1(1); |
| 74 |
TestResource d2(1); |
| 75 |
A1 const a1(&d1); |
| 76 |
A1 const a2(&d2); |
| 77 |
|
| 78 |
assert(!(a1 != a2)); |
| 79 |
assert(d1.checkIsEqualCalledEq(1)); |
| 80 |
assert(d2.checkIsEqualCalledEq(0)); |
| 81 |
|
| 82 |
d1.reset(); |
| 83 |
|
| 84 |
assert(!(a2 != a1)); |
| 85 |
assert(d1.checkIsEqualCalledEq(0)); |
| 86 |
assert(d2.checkIsEqualCalledEq(1)); |
| 87 |
} |
| 88 |
// not equal different types |
| 89 |
{ |
| 90 |
TestResource d1; |
| 91 |
TestResource1 d2; |
| 92 |
A1 const a1(&d1); |
| 93 |
A2 const a2(&d2); |
| 94 |
|
| 95 |
assert(a1 != a2); |
| 96 |
assert(d1.checkIsEqualCalledEq(1)); |
| 97 |
assert(d2.checkIsEqualCalledEq(0)); |
| 98 |
|
| 99 |
d1.reset(); |
| 100 |
|
| 101 |
assert(a2 != a1); |
| 102 |
assert(d1.checkIsEqualCalledEq(0)); |
| 103 |
assert(d2.checkIsEqualCalledEq(1)); |
| 104 |
} |
| 105 |
|
| 106 |
return 0; |
| 107 |
} |