1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <memory> 11 12// unique_ptr 13 14// test release 15 16#include <memory> 17#include <cassert> 18 19#include "test_macros.h" 20#include "unique_ptr_test_helper.h" 21 22template <bool IsArray> 23void test_basic() { 24 typedef typename std::conditional<IsArray, A[], A>::type VT; 25 const int expect_alive = IsArray ? 3 : 1; 26#if TEST_STD_VER >= 11 27 { 28 using U = std::unique_ptr<VT>; 29 U u; ((void)u); 30 ASSERT_NOEXCEPT(u.release()); 31 } 32#endif 33 { 34 std::unique_ptr<VT> p(newValue<VT>(expect_alive)); 35 assert(A::count == expect_alive); 36 A* ap = p.get(); 37 A* a = p.release(); 38 assert(A::count == expect_alive); 39 assert(p.get() == nullptr); 40 assert(ap == a); 41 assert(a != nullptr); 42 43 if (IsArray) 44 delete[] a; 45 else 46 delete a; 47 48 assert(A::count == 0); 49 } 50 assert(A::count == 0); 51} 52 53int main() { 54 test_basic</*IsArray*/ false>(); 55 test_basic<true>(); 56} 57