• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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()22 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     assert(A::count == expect_alive);
35     A* ap = p.get();
36     A* a = p.release();
37     assert(A::count == expect_alive);
38     assert(p.get() == nullptr);
39     assert(ap == a);
40     assert(a != nullptr);
41 
42     if (IsArray)
43       delete[] a;
44     else
45       delete a;
46 
47     assert(A::count == 0);
48   }
49   assert(A::count == 0);
50 }
51 
main(int,char **)52 int main(int, char**) {
53   test_basic</*IsArray*/ false>();
54   test_basic<true>();
55 
56   return 0;
57 }
58