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 // template <class X> class auto_ptr; 13 14 // template<class Y> auto_ptr& operator=(auto_ptr<Y>& a) throw(); 15 16 // REQUIRES: c++98 || c++03 || c++11 || c++14 17 18 #include <memory> 19 #include <cassert> 20 21 #include "../AB.h" 22 23 void test()24test() 25 { 26 { 27 B* p1 = new B(1); 28 std::auto_ptr<B> ap1(p1); 29 A* p2 = new A(2); 30 std::auto_ptr<A> ap2(p2); 31 assert(A::count == 2); 32 assert(B::count == 1); 33 assert(ap1.get() == p1); 34 assert(ap2.get() == p2); 35 std::auto_ptr<A>& apr = ap2 = ap1; 36 assert(&apr == &ap2); 37 assert(A::count == 1); 38 assert(B::count == 1); 39 assert(ap1.get() == 0); 40 assert(ap2.get() == p1); 41 } 42 assert(A::count == 0); 43 assert(B::count == 0); 44 } 45 main()46int main() 47 { 48 test(); 49 } 50