51 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <memory>10 11// template <class X> class auto_ptr;12 13// template<class Y> auto_ptr& operator=(auto_ptr<Y>& a) throw();14 15// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS16 17#include <memory>18#include <cassert>19 20#include "../AB.h"21 22void23test()24{25 {26 B* p1 = new B(1);27 const std::auto_ptr<B> ap1(p1);28 A* p2 = new A(2);29 std::auto_ptr<A> ap2(p2);30 assert(A::count == 2);31 assert(B::count == 1);32 assert(ap1.get() == p1);33 assert(ap2.get() == p2);34 std::auto_ptr<A>& apr = ap2 = ap1;35 assert(&apr == &ap2);36 assert(A::count == 1);37 assert(B::count == 1);38 assert(ap1.get() == 0);39 assert(ap2.get() == p1);40 }41 assert(A::count == 0);42 assert(B::count == 0);43}44 45int main(int, char**)46{47 test();48 49 return 0;50}51