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 // Can't assign from const lvalue 17 18 #include <memory> 19 #include <utility> 20 #include <cassert> 21 22 #include "../../deleter.h" 23 24 struct A 25 { 26 static int count; 27 A() {++count;} 28 A(const A&) {++count;} 29 virtual ~A() {--count;} 30 }; 31 32 int A::count = 0; 33 34 struct B 35 : public A 36 { 37 static int count; 38 B() {++count;} 39 B(const B&) {++count;} 40 virtual ~B() {--count;} 41 }; 42 43 int B::count = 0; 44 45 int main() 46 { 47 { 48 Deleter<B> db(5); 49 const std::unique_ptr<B, Deleter<B>&> s(new B, db); 50 A* p = s.get(); 51 Deleter<A> da(6); 52 std::unique_ptr<A, Deleter<A>&> s2(new A, da); 53 s2 = s; 54 assert(s2.get() == p); 55 assert(s.get() == 0); 56 assert(A::count == 1); 57 assert(B::count == 1); 58 assert(s2.get_deleter().state() == 5); 59 } 60 assert(A::count == 0); 61 assert(B::count == 0); 62 } 63