Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.pt/auto_ptr.C

raw
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;
10
11 explicit auto_ptr(X* p =0) throw() : px(p) {}
12 auto_ptr(auto_ptr& r) throw() : px(r.release()) {} // { dg-message "note" "" { target c++14_down } } candidate
13 template<typename Y>
14 auto_ptr(auto_ptr<Y>& r) throw() : px(r.release()) {}
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) {}
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
42 struct Base { Base() {} virtual ~Base() {} };
43 struct Derived : Base { Derived() {} };
44
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-message "initializing" "" { target c++14_down } }
48
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 "rvalue" "" { target c++14_down } } no usable copy ctor
55 }