]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / utilities / memory / unique.ptr / unique.ptr.runtime / null_ctor.pass.cpp
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 // The deleter is not called if get() == 0
15
16 #include <memory>
17 #include <cassert>
18
19 #include "test_macros.h"
20
21 class Deleter
22 {
23     int state_;
24
25     Deleter(Deleter&);
26     Deleter& operator=(Deleter&);
27
28 public:
29     Deleter() : state_(0) {}
30
31     int state() const {return state_;}
32
33     void operator()(void*) {++state_;}
34 };
35
36 int main()
37 {
38     Deleter d;
39     assert(d.state() == 0);
40     {
41     std::unique_ptr<int[], Deleter&> p(nullptr, d);
42     assert(p.get() == 0);
43     assert(&p.get_deleter() == &d);
44     }
45 #if defined(_LIBCPP_VERSION)
46     {
47     // The standard only requires the constructor accept nullptr, but libc++
48     // also supports the literal 0.
49     std::unique_ptr<int[], Deleter&> p(0, d);
50     assert(p.get() == 0);
51     assert(&p.get_deleter() == &d);
52     }
53 #endif
54     assert(d.state() == 0);
55 }