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 <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()44int main() 45 { 46 { 47 Deleter<B> db(5); 48 const std::unique_ptr<B, Deleter<B>&> s(new B, db); 49 A* p = s.get(); 50 Deleter<A> da(6); 51 std::unique_ptr<A, Deleter<A>&> s2(new A, da); 52 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 } 59 assert(A::count == 0); 60 assert(B::count == 0); 61 } 62