2 template <typename Y> struct auto_ptr_ref {
4 auto_ptr_ref(Y* p) : py(p) {}
6 template<typename X> struct auto_ptr {
9 typedef X element_type;
11 explicit auto_ptr(X* p =0) throw() : px(p) {}
12 auto_ptr(auto_ptr& r) throw() : px(r.release()) {} // { dg-error "" } candidate
14 auto_ptr(auto_ptr<Y>& r) throw() : px(r.release()) {}// { dg-error "" } candidate
16 auto_ptr& operator=(auto_ptr& r) throw() {
20 template<typename Y> auto_ptr& operator=(auto_ptr<Y>& r) throw() {
25 ~auto_ptr() { delete px; }
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; }
33 auto_ptr(auto_ptr_ref<X> r) throw() : px(r.py) {} // { dg-error "" } candidate
34 template<typename Y> operator auto_ptr_ref<Y>() throw() {
35 return auto_ptr_ref<Y>(release());
37 template<typename Y> operator auto_ptr<Y>() throw() {
38 return auto_ptr<Y>(release());
42 struct Base { Base() {} virtual ~Base() {} };
43 struct Derived : Base { Derived() {}; };
45 auto_ptr<Derived> f() { auto_ptr<Derived> null(0); return null; }
46 void g(auto_ptr<Derived>) { }
47 void h(auto_ptr<Base>) { }
50 auto_ptr<Base> x(f());
51 auto_ptr<Derived> y(f());
54 h(f()); // { dg-error "" } no usable copy ctor