70 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// test op*()14 15#include <cassert>16#include <memory>17#include <utility>18#include <vector>19 20#include "test_macros.h"21 22#if TEST_STD_VER >= 1123struct ThrowDereference {24 TEST_CONSTEXPR_CXX23 ThrowDereference& operator*() noexcept(false);25 TEST_CONSTEXPR_CXX23 operator bool() const { return false; }26};27 28struct Deleter {29 using pointer = ThrowDereference;30 TEST_CONSTEXPR_CXX23 void operator()(ThrowDereference&) const {}31};32#endif33 34TEST_CONSTEXPR_CXX23 bool test() {35 {36 std::unique_ptr<int> p(new int(3));37 assert(*p == 3);38 ASSERT_NOEXCEPT(*p);39 }40#if TEST_STD_VER >= 1141 {42 std::unique_ptr<std::vector<int>> p(new std::vector<int>{3, 4, 5});43 assert((*p)[0] == 3);44 assert((*p)[1] == 4);45 assert((*p)[2] == 5);46 ASSERT_NOEXCEPT(*p);47 }48 {49 std::unique_ptr<ThrowDereference> p;50 ASSERT_NOEXCEPT(*p);51 }52 {53 // The noexcept status of *unique_ptr<>::pointer should be propagated.54 std::unique_ptr<ThrowDereference, Deleter> p;55 ASSERT_NOT_NOEXCEPT(*p);56 }57#endif58 59 return true;60}61 62int main(int, char**) {63 test();64#if TEST_STD_VER >= 2365 static_assert(test());66#endif67 68 return 0;69}70