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 // unique_ptr 12 13 // test release 14 15 #include <memory> 16 #include <cassert> 17 18 #include "test_macros.h" 19 #include "unique_ptr_test_helper.h" 20 21 template <bool IsArray> test_basic()22TEST_CONSTEXPR_CXX23 void test_basic() { 23 typedef typename std::conditional<IsArray, A[], A>::type VT; 24 const int expect_alive = IsArray ? 3 : 1; 25 #if TEST_STD_VER >= 11 26 { 27 using U = std::unique_ptr<VT>; 28 U u; ((void)u); 29 ASSERT_NOEXCEPT(u.release()); 30 } 31 #endif 32 { 33 std::unique_ptr<VT> p(newValue<VT>(expect_alive)); 34 if (!TEST_IS_CONSTANT_EVALUATED) 35 assert(A::count == expect_alive); 36 A* ap = p.get(); 37 A* a = p.release(); 38 if (!TEST_IS_CONSTANT_EVALUATED) 39 assert(A::count == expect_alive); 40 assert(p.get() == nullptr); 41 assert(ap == a); 42 assert(a != nullptr); 43 44 if (IsArray) 45 delete[] a; 46 else 47 delete a; 48 49 if (!TEST_IS_CONSTANT_EVALUATED) 50 assert(A::count == 0); 51 } 52 if (!TEST_IS_CONSTANT_EVALUATED) 53 assert(A::count == 0); 54 } 55 test()56TEST_CONSTEXPR_CXX23 bool test() { 57 test_basic</*IsArray*/ false>(); 58 test_basic<true>(); 59 60 return true; 61 } 62 main(int,char **)63int main(int, char**) { 64 test(); 65 #if TEST_STD_VER >= 23 66 static_assert(test()); 67 #endif 68 69 return 0; 70 } 71