| 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 | // <memory> |
| 10 | |
| 11 | // shared_ptr |
| 12 | |
| 13 | // template <class T> |
| 14 | // bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 15 | // template <class T> |
| 16 | // bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 17 | // template <class T> |
| 18 | // bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 19 | // template <class T> |
| 20 | // bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 21 | // template <class T> |
| 22 | // bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 23 | // template <class T> |
| 24 | // bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 25 | // template <class T> |
| 26 | // bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 27 | // template <class T> |
| 28 | // bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 29 | // template <class T> |
| 30 | // bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 31 | // template <class T> |
| 32 | // bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 33 | // template <class T> |
| 34 | // bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 35 | // template <class T> |
| 36 | // bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 37 | // template<class T> |
| 38 | // strong_ordering operator<=>(shared_ptr<T> const& x, nullptr_t) noexcept; // C++20 |
| 39 | |
| 40 | #include <cassert> |
| 41 | #include <cstddef> |
| 42 | #include <memory> |
| 43 | |
| 44 | #include "test_macros.h" |
| 45 | #include "test_comparisons.h" |
| 46 | |
| 47 | void do_nothing(int*) {} |
| 48 | |
| 49 | int main(int, char**) |
| 50 | { |
| 51 | AssertComparisonsAreNoexcept<std::shared_ptr<int>, nullptr_t>(); |
| 52 | AssertComparisonsAreNoexcept<nullptr_t, std::shared_ptr<int> >(); |
| 53 | AssertComparisonsReturnBool<std::shared_ptr<int>, nullptr_t>(); |
| 54 | AssertComparisonsReturnBool<nullptr_t, std::shared_ptr<int> >(); |
| 55 | #if TEST_STD_VER >= 20 |
| 56 | AssertOrderAreNoexcept<std::shared_ptr<int>>(); |
| 57 | AssertOrderReturn<std::strong_ordering, std::shared_ptr<int>>(); |
| 58 | #endif |
| 59 | |
| 60 | const std::shared_ptr<int> p1(new int(1)); |
| 61 | assert(!(p1 == nullptr)); |
| 62 | assert(!(nullptr == p1)); |
| 63 | assert(!(p1 < nullptr)); |
| 64 | assert((nullptr < p1)); |
| 65 | assert(!(p1 <= nullptr)); |
| 66 | assert((nullptr <= p1)); |
| 67 | assert((p1 > nullptr)); |
| 68 | assert(!(nullptr > p1)); |
| 69 | assert((p1 >= nullptr)); |
| 70 | assert(!(nullptr >= p1)); |
| 71 | #if TEST_STD_VER >= 20 |
| 72 | assert((nullptr <=> p1) == std::strong_ordering::less); |
| 73 | assert((p1 <=> nullptr) == std::strong_ordering::greater); |
| 74 | #endif |
| 75 | |
| 76 | const std::shared_ptr<int> p2; |
| 77 | assert((p2 == nullptr)); |
| 78 | assert((nullptr == p2)); |
| 79 | assert(!(p2 < nullptr)); |
| 80 | assert(!(nullptr < p2)); |
| 81 | assert((p2 <= nullptr)); |
| 82 | assert((nullptr <= p2)); |
| 83 | assert(!(p2 > nullptr)); |
| 84 | assert(!(nullptr > p2)); |
| 85 | assert((p2 >= nullptr)); |
| 86 | assert((nullptr >= p2)); |
| 87 | #if TEST_STD_VER >= 20 |
| 88 | assert((p2 <=> nullptr) == std::strong_ordering::equivalent); |
| 89 | assert((nullptr <=> p2) == std::strong_ordering::equivalent); |
| 90 | #endif |
| 91 | |
| 92 | #if TEST_STD_VER >= 17 |
| 93 | const std::shared_ptr<int[]> p3(new int[1]); |
| 94 | assert(!(p3 == nullptr)); |
| 95 | assert(!(nullptr == p3)); |
| 96 | assert(!(p3 < nullptr)); |
| 97 | assert((nullptr < p3)); |
| 98 | assert(!(p3 <= nullptr)); |
| 99 | assert((nullptr <= p3)); |
| 100 | assert((p3 > nullptr)); |
| 101 | assert(!(nullptr > p3)); |
| 102 | assert((p3 >= nullptr)); |
| 103 | assert(!(nullptr >= p3)); |
| 104 | # if TEST_STD_VER >= 20 |
| 105 | assert((p3 <=> nullptr) == std::strong_ordering::greater); |
| 106 | assert((nullptr <=> p3) == std::strong_ordering::less); |
| 107 | # endif |
| 108 | |
| 109 | const std::shared_ptr<int[]> p4; |
| 110 | assert((p4 == nullptr)); |
| 111 | assert((nullptr == p4)); |
| 112 | assert(!(p4 < nullptr)); |
| 113 | assert(!(nullptr < p4)); |
| 114 | assert((p4 <= nullptr)); |
| 115 | assert((nullptr <= p4)); |
| 116 | assert(!(p4 > nullptr)); |
| 117 | assert(!(nullptr > p4)); |
| 118 | assert((p4 >= nullptr)); |
| 119 | assert((nullptr >= p4)); |
| 120 | # if TEST_STD_VER >= 20 |
| 121 | assert((p4 <=> nullptr) == std::strong_ordering::equivalent); |
| 122 | assert((nullptr <=> p4) == std::strong_ordering::equivalent); |
| 123 | # endif |
| 124 | #endif |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |