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 // Implicit version
19 
20 #include <memory>
21 #include <cassert>
22 
23 #include "../../deleter.h"
24 
25 struct A
26 {
27     static int count;
AA28     A() {++count;}
AA29     A(const A&) {++count;}
~AA30     virtual ~A() {--count;}
31 };
32 
33 int A::count = 0;
34 
35 struct B
36     : public A
37 {
38     static int count;
BB39     B() {++count;}
BB40     B(const B&) {++count;}
~BB41     virtual ~B() {--count;}
42 };
43 
44 int B::count = 0;
45 
main()46 int main()
47 {
48     {
49     std::unique_ptr<B[], Deleter<B[]> > s(new B);
50     A* p = s.get();
51     std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s);
52     assert(s2.get() == p);
53     assert(s.get() == 0);
54     assert(A::count == 1);
55     assert(B::count == 1);
56     assert(s2.get_deleter().state() == 5);
57     assert(s.get_deleter().state() == 0);
58     }
59     assert(A::count == 0);
60     assert(B::count == 0);
61 }
62