//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y> explicit shared_ptr(auto_ptr<Y>&& r);
#include<memory>#include<new>#include<cstdlib>#include<cassert>boolthrow_next=false;void*operatornew(std::size_ts)throw(std::bad_alloc){if(throw_next)throwstd::bad_alloc();returnstd::malloc(s);}voidoperatordelete(void*p)throw(){std::free(p);}structB{staticintcount;B(){++count;}B(constB&){++count;}virtual~B(){--count;}};intB::count=0;structA:publicB{staticintcount;A(){++count;}A(constA&){++count;}~A(){--count;}};intA::count=0;intmain(){{std::auto_ptr<A>ptr(newA);A*raw_ptr=ptr.get();#ifdef _LIBCPP_MOVEstd::shared_ptr<B>p(std::move(ptr));#elsestd::shared_ptr<B>p(ptr);#endifassert(A::count==1);assert(B::count==1);assert(p.use_count()==1);assert(p.get()==raw_ptr);assert(ptr.get()==0);}assert(A::count==0);{std::auto_ptr<A>ptr(newA);A*raw_ptr=ptr.get();throw_next=true;try{#ifdef _LIBCPP_MOVEstd::shared_ptr<B>p(std::move(ptr));#elsestd::shared_ptr<B>p(ptr);#endifassert(false);}catch(...){assert(A::count==1);assert(B::count==1);assert(ptr.get()==raw_ptr);}}assert(A::count==0);}