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 // UNSUPPORTED: c++98, c++03
11 
12 // <memory>
13 
14 // unique_ptr
15 
16 // FIXME(EricWF): This test contains tests for constructing a unique_ptr from NULL.
17 // The behavior demonstrated in this test is not meant to be standard; It simply
18 // tests the current status quo in libc++.
19 
20 #include <memory>
21 #include <cassert>
22 
23 #include "test_macros.h"
24 #include "unique_ptr_test_helper.h"
25 
26 template <class VT>
test_pointer_ctor()27 void test_pointer_ctor() {
28   {
29     std::unique_ptr<VT> p(0);
30     assert(p.get() == 0);
31   }
32   {
33     std::unique_ptr<VT, Deleter<VT> > p(0);
34     assert(p.get() == 0);
35     assert(p.get_deleter().state() == 0);
36   }
37 }
38 
39 template <class VT>
test_pointer_deleter_ctor()40 void test_pointer_deleter_ctor() {
41   {
42     std::default_delete<VT> d;
43     std::unique_ptr<VT> p(0, d);
44     assert(p.get() == 0);
45   }
46   {
47     std::unique_ptr<VT, Deleter<VT> > p(0, Deleter<VT>(5));
48     assert(p.get() == 0);
49     assert(p.get_deleter().state() == 5);
50   }
51   {
52     NCDeleter<VT> d(5);
53     std::unique_ptr<VT, NCDeleter<VT>&> p(0, d);
54     assert(p.get() == 0);
55     assert(p.get_deleter().state() == 5);
56   }
57   {
58     NCConstDeleter<VT> d(5);
59     std::unique_ptr<VT, NCConstDeleter<VT> const&> p(0, d);
60     assert(p.get() == 0);
61     assert(p.get_deleter().state() == 5);
62   }
63 }
64 
main()65 int main() {
66   {
67     // test_pointer_ctor<int>();
68     test_pointer_deleter_ctor<int>();
69   }
70   {
71     test_pointer_ctor<int[]>();
72     test_pointer_deleter_ctor<int[]>();
73   }
74 }
75