• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 assignment
15 
16 // test converting move assignment with reference deleters
17 
18 #include <memory>
19 #include <cassert>
20 
21 #include "../../deleter.h"
22 
23 struct A
24 {
25     static int count;
AA26     A() {++count;}
AA27     A(const A&) {++count;}
~AA28     virtual ~A() {--count;}
29 };
30 
31 int A::count = 0;
32 
33 struct B
34     : public A
35 {
36     static int count;
BB37     B() {++count;}
BB38     B(const B&) {++count;}
~BB39     virtual ~B() {--count;}
40 };
41 
42 int B::count = 0;
43 
main()44 int main()
45 {
46     {
47     CDeleter<B> db(5);
48     std::unique_ptr<B, CDeleter<B>&> s(new B, db);
49     A* p = s.get();
50     CDeleter<A> da(6);
51     std::unique_ptr<A, CDeleter<A>&> s2(new A, da);
52     s2 = std::move(s);
53     assert(s2.get() == p);
54     assert(s.get() == 0);
55     assert(A::count == 1);
56     assert(B::count == 1);
57     assert(s.get_deleter().state() == 5);
58     assert(s2.get_deleter().state() == 5);
59     }
60     assert(A::count == 0);
61     assert(B::count == 0);
62 }
63