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; 26 A() {++count;} 27 A(const A&) {++count;} 28 virtual ~A() {--count;} 29 }; 30 31 int A::count = 0; 32 33 struct B 34 : public A 35 { 36 static int count; 37 B() {++count;} 38 B(const B&) {++count;} 39 virtual ~B() {--count;} 40 }; 41 42 int B::count = 0; 43 44 int main() 45 { 46 { 47 const std::unique_ptr<B, Deleter<B> > s(new B); 48 A* p = s.get(); 49 std::unique_ptr<A, Deleter<A> > s2; 50 s2 = s; 51 assert(s2.get() == p); 52 assert(s.get() == 0); 53 assert(A::count == 1); 54 assert(B::count == 1); 55 assert(s2.get_deleter().state() == 5); 56 assert(s.get_deleter().state() == 0); 57 } 58 assert(A::count == 0); 59 assert(B::count == 0); 60 } 61