1// { dg-do assemble } 2template <typename Y> struct auto_ptr_ref { 3 Y* py; 4 auto_ptr_ref(Y* p) : py(p) {} 5}; 6template<typename X> struct auto_ptr { 7 X* px; 8 public: 9 typedef X element_type; 10 11 explicit auto_ptr(X* p =0) throw() : px(p) {} 12 auto_ptr(auto_ptr& r) throw() : px(r.release()) {} // { dg-message "note" } candidate 13 template<typename Y> 14 auto_ptr(auto_ptr<Y>& r) throw() : px(r.release()) {}// { dg-message "note" } candidate 15 16 auto_ptr& operator=(auto_ptr& r) throw() { 17 reset(r.release()); 18 return *this; 19 } 20 template<typename Y> auto_ptr& operator=(auto_ptr<Y>& r) throw() { 21 reset(r.release()); 22 return *this; 23 } 24 25 ~auto_ptr() { delete px; } 26 27 X& operator*() const throw() { return *px; } 28 X* operator->() const throw() { return px; } 29 X* get() const throw() { return px; } 30 X* release() throw() { X* p=px; px=0; return p; } 31 void reset(X* p=0) throw() { if (px != p) delete px, px = p; } 32 33 auto_ptr(auto_ptr_ref<X> r) throw() : px(r.py) {} // { dg-message "candidate" } 34 template<typename Y> operator auto_ptr_ref<Y>() throw() { 35 return auto_ptr_ref<Y>(release()); 36 } 37 template<typename Y> operator auto_ptr<Y>() throw() { 38 return auto_ptr<Y>(release()); 39 } 40}; 41 42struct Base { Base() {} virtual ~Base() {} }; 43struct Derived : Base { Derived() {} }; 44 45auto_ptr<Derived> f() { auto_ptr<Derived> null(0); return null; } 46void g(auto_ptr<Derived>) { } 47void h(auto_ptr<Base>) { } 48 49int main() { 50 auto_ptr<Base> x(f()); 51 auto_ptr<Derived> y(f()); 52 x = y; 53 g(f()); 54 h(f()); // { dg-error "match" "match" } no usable copy ctor 55// { dg-error "initializing" "init" { target *-*-* } 54 } 56} 57