Merged trunk at revision 161680 into branch.
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.pt / auto_ptr.C
blob3a587d8738ea9c4587db6dec1f3c1e47f94c4d13
1 // { dg-do assemble  }
2 template <typename Y> struct auto_ptr_ref {
3   Y* py;
4   auto_ptr_ref(Y* p) : py(p) {}
5 };
6 template<typename X> struct auto_ptr {
7    X* px;
8  public:
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-message "note" } candidate
13    template<typename Y>
14       auto_ptr(auto_ptr<Y>& r) throw() : px(r.release()) {}// { dg-message "note" } candidate
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    }
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-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    }
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>) { }      // { dg-error "initializing" }
49 int 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