xref: /aosp_15_r20/external/cronet/third_party/libc++/src/test/libcxx/utilities/smartptr/unique.ptr/null.pass.cpp (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 // UNSUPPORTED: c++03
10 
11 // <memory>
12 
13 // unique_ptr
14 
15 // FIXME(EricWF): This test contains tests for constructing a unique_ptr from NULL.
16 // The behavior demonstrated in this test is not meant to be standard; It simply
17 // tests the current status quo in libc++.
18 
19 #include <memory>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 #include "unique_ptr_test_helper.h"
24 
25 template <class VT>
test_pointer_ctor()26 TEST_CONSTEXPR_CXX23 void test_pointer_ctor() {
27   {
28     std::unique_ptr<VT> p(0);
29     assert(p.get() == 0);
30   }
31   {
32     std::unique_ptr<VT, Deleter<VT> > p(0);
33     assert(p.get() == 0);
34     assert(p.get_deleter().state() == 0);
35   }
36 }
37 
38 template <class VT>
test_pointer_deleter_ctor()39 TEST_CONSTEXPR_CXX23 void test_pointer_deleter_ctor() {
40   {
41     std::default_delete<VT> d;
42     std::unique_ptr<VT> p(0, d);
43     assert(p.get() == 0);
44   }
45   {
46     std::unique_ptr<VT, Deleter<VT> > p(0, Deleter<VT>(5));
47     assert(p.get() == 0);
48     assert(p.get_deleter().state() == 5);
49   }
50   {
51     NCDeleter<VT> d(5);
52     std::unique_ptr<VT, NCDeleter<VT>&> p(0, d);
53     assert(p.get() == 0);
54     assert(p.get_deleter().state() == 5);
55   }
56   {
57     NCConstDeleter<VT> d(5);
58     std::unique_ptr<VT, NCConstDeleter<VT> const&> p(0, d);
59     assert(p.get() == 0);
60     assert(p.get_deleter().state() == 5);
61   }
62 }
63 
test()64 TEST_CONSTEXPR_CXX23 bool test() {
65   {
66     // test_pointer_ctor<int>();
67     test_pointer_deleter_ctor<int>();
68   }
69   {
70     test_pointer_ctor<int[]>();
71     test_pointer_deleter_ctor<int[]>();
72   }
73 
74   return true;
75 }
76 
main(int,char **)77 int main(int, char**) {
78   test();
79 #if TEST_STD_VER >= 23
80   static_assert(test());
81 #endif
82 
83   return 0;
84 }
85