brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.1 KiB · 5ef9c4b Raw
142 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <memory>10 11// unique_ptr12 13// template <class T, class D>14//     constexpr bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept; // constexpr since C++2315// template <class T, class D>16//     bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;           // removed in C++2017// template <class T, class D>18//     bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;           // removed in C++2019// template <class T, class D>20//     bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;           // removed in C++2021// template <class T, class D>22//     constexpr bool operator<(const unique_ptr<T, D>& x, nullptr_t);           // constexpr since C++2323// template <class T, class D>24//     constexpr bool operator<(nullptr_t, const unique_ptr<T, D>& y);           // constexpr since C++2325// template <class T, class D>26//     constexpr bool operator<=(const unique_ptr<T, D>& x, nullptr_t);          // constexpr since C++2327// template <class T, class D>28//     constexpr bool operator<=(nullptr_t, const unique_ptr<T, D>& y);          // constexpr since C++2329// template <class T, class D>30//     constexpr bool operator>(const unique_ptr<T, D>& x, nullptr_t);           // constexpr since C++2331// template <class T, class D>32//     constexpr bool operator>(nullptr_t, const unique_ptr<T, D>& y);           // constexpr since C++2333// template <class T, class D>34//     constexpr bool operator>=(const unique_ptr<T, D>& x, nullptr_t);          // constexpr since C++2335// template <class T, class D>36//     constexpr bool operator>=(nullptr_t, const unique_ptr<T, D>& y);          // constexpr since C++2337// template<class T, class D>38//   requires three_way_comparable<typename unique_ptr<T, D>::pointer>39//   constexpr compare_three_way_result_t<typename unique_ptr<T, D>::pointer>40//     operator<=>(const unique_ptr<T, D>& x, nullptr_t);                        // C++2041 42#include <cassert>43#include <cstddef>44#include <memory>45 46#include "test_macros.h"47#include "test_comparisons.h"48 49TEST_CONSTEXPR_CXX23 bool test() {50  if (!TEST_IS_CONSTANT_EVALUATED) {51    AssertEqualityAreNoexcept<std::unique_ptr<int>, nullptr_t>();52    AssertEqualityAreNoexcept<nullptr_t, std::unique_ptr<int> >();53    AssertComparisonsReturnBool<std::unique_ptr<int>, nullptr_t>();54    AssertComparisonsReturnBool<nullptr_t, std::unique_ptr<int> >();55#if TEST_STD_VER >= 2056    AssertOrderReturn<std::strong_ordering, std::unique_ptr<int>, nullptr_t>();57    AssertOrderReturn<std::strong_ordering, nullptr_t, std::unique_ptr<int>>();58#endif59  }60 61  const std::unique_ptr<int> p1(new int(1));62  assert(!(p1 == nullptr));63  assert(!(nullptr == p1));64  // A pointer to allocated storage and a nullptr can't be compared at compile-time65  if (!TEST_IS_CONSTANT_EVALUATED) {66    assert(!(p1 < nullptr));67    assert((nullptr < p1));68    assert(!(p1 <= nullptr));69    assert((nullptr <= p1));70    assert((p1 > nullptr));71    assert(!(nullptr > p1));72    assert((p1 >= nullptr));73    assert(!(nullptr >= p1));74#if TEST_STD_VER >= 2075    assert((p1 <=> nullptr) == std::strong_ordering::greater);76    assert((nullptr <=> p1) == std::strong_ordering::less);77#endif78  }79 80  const std::unique_ptr<int> 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  assert(!(p2 > nullptr));88  assert(!(nullptr > p2));89  assert((p2 >= nullptr));90  assert((nullptr >= p2));91#if TEST_STD_VER >= 2092  assert((p2 <=> nullptr) == std::strong_ordering::equivalent);93  assert((nullptr <=> p2) == std::strong_ordering::equivalent);94#endif95 96  const std::unique_ptr<int[]> p3(new int[1]);97  assert(!(p3 == nullptr));98  assert(!(nullptr == p3));99  // A pointer to allocated storage and a nullptr can't be compared at compile-time100  if (!TEST_IS_CONSTANT_EVALUATED) {101    assert(!(p3 < nullptr));102    assert((nullptr < p3));103    assert(!(p3 <= nullptr));104    assert((nullptr <= p3));105    assert((p3 > nullptr));106    assert(!(nullptr > p3));107    assert((p3 >= nullptr));108    assert(!(nullptr >= p3));109#if TEST_STD_VER >= 20110    assert((nullptr <=> p3) == std::strong_ordering::less);111    assert((p3 <=> nullptr) == std::strong_ordering::greater);112#endif113  }114 115  const std::unique_ptr<int[]> p4;116  assert((p4 == nullptr));117  assert((nullptr == p4));118  assert(!(p4 < nullptr));119  assert(!(nullptr < p4));120  assert((p4 <= nullptr));121  assert((nullptr <= p4));122  assert(!(p4 > nullptr));123  assert(!(nullptr > p4));124  assert((p4 >= nullptr));125  assert((nullptr >= p4));126#if TEST_STD_VER >= 20127  assert((p4 <=> nullptr) == std::strong_ordering::equivalent);128  assert((nullptr <=> p4) == std::strong_ordering::equivalent);129#endif130 131  return true;132}133 134int main(int, char**) {135  test();136#if TEST_STD_VER >= 23137  static_assert(test());138#endif139 140  return 0;141}142