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 unique_ptr converting move ctor
15 
16 // test converting move ctor.  Should only require a MoveConstructible deleter, or if
17 //    deleter is a reference, not even that.
18 // Explicit version
19 
20 #include <memory>
21 #include <utility>
22 #include <cassert>
23 
24 #include "../../deleter.h"
25 
26 struct A
27 {
28     static int count;
AA29     A() {++count;}
AA30     A(const A&) {++count;}
~AA31     virtual ~A() {--count;}
32 };
33 
34 int A::count = 0;
35 
36 struct B
37     : public A
38 {
39     static int count;
BB40     B() {++count;}
BB41     B(const B&) {++count;}
~BB42     virtual ~B() {--count;}
43 };
44 
45 int B::count = 0;
46 
main()47 int main()
48 {
49     {
50     std::unique_ptr<B, Deleter<B> > s(new B);
51     A* p = s.get();
52     std::unique_ptr<A, Deleter<A> > s2(s);
53     assert(s2.get() == p);
54     assert(s.get() == 0);
55     assert(A::count == 1);
56     assert(B::count == 1);
57     assert(s2.get_deleter().state() == 5);
58     assert(s.get_deleter().state() == 0);
59     }
60     assert(A::count == 0);
61     assert(B::count == 0);
62 }
63