mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-03-31 09:20:44 +08:00
new
From-SVN: r20021
This commit is contained in:
parent
f098395833
commit
60f06d2f91
15
gcc/testsuite/g++.old-deja/g++.other/delete1.C
Normal file
15
gcc/testsuite/g++.old-deja/g++.other/delete1.C
Normal file
@ -0,0 +1,15 @@
|
||||
//Build don't link:
|
||||
struct cl_heap_ring{
|
||||
void operator delete (void* ptr) { }
|
||||
cl_heap_ring ()
|
||||
{ }
|
||||
};
|
||||
|
||||
struct cl_heap_null_ring : public cl_heap_ring {
|
||||
void operator delete (void* ptr) { }
|
||||
};
|
||||
|
||||
void f()
|
||||
{
|
||||
new cl_heap_null_ring();
|
||||
}
|
13
gcc/testsuite/g++.old-deja/g++.other/virtual1.C
Normal file
13
gcc/testsuite/g++.old-deja/g++.other/virtual1.C
Normal file
@ -0,0 +1,13 @@
|
||||
// Build don't link:
|
||||
|
||||
struct S0 { virtual void f1 () { } };
|
||||
|
||||
struct S1 : virtual public S0 { virtual void f1 () { } };
|
||||
|
||||
struct S2 : public S1 { virtual void f1 () { } };
|
||||
|
||||
struct S3 : virtual public S0 { virtual void f1 () { } };
|
||||
|
||||
struct S4 : public S3 { };
|
||||
|
||||
void creator () { new S4; }
|
54
gcc/testsuite/g++.old-deja/g++.pt/auto_ptr.C
Normal file
54
gcc/testsuite/g++.old-deja/g++.pt/auto_ptr.C
Normal file
@ -0,0 +1,54 @@
|
||||
template <typename Y> struct auto_ptr_ref {
|
||||
Y* py;
|
||||
auto_ptr_ref(Y* p) : py(p) {}
|
||||
};
|
||||
template<typename X> struct auto_ptr {
|
||||
X* px;
|
||||
public:
|
||||
typedef X element_type;
|
||||
|
||||
explicit auto_ptr(X* p =0) throw() : px(p) {}
|
||||
auto_ptr(auto_ptr& r) throw() : px(r.release()) {}
|
||||
template<typename Y>
|
||||
auto_ptr(auto_ptr<Y>& r) throw() : px(r.release()) {}
|
||||
|
||||
auto_ptr& operator=(auto_ptr& r) throw() {
|
||||
reset(r.release());
|
||||
return *this;
|
||||
}
|
||||
template<typename Y> auto_ptr& operator=(auto_ptr<Y>& r) throw() {
|
||||
reset(r.release());
|
||||
return *this;
|
||||
}
|
||||
|
||||
~auto_ptr() { delete px; }
|
||||
|
||||
X& operator*() const throw() { return *px; }
|
||||
X* operator->() const throw() { return px; }
|
||||
X* get() const throw() { return px; }
|
||||
X* release() throw() { X* p=px; px=0; return p; }
|
||||
void reset(X* p=0) throw() { if (px != p) delete px, px = p; }
|
||||
|
||||
auto_ptr(auto_ptr_ref<X> r) throw() : px(r.py) {}
|
||||
template<typename Y> operator auto_ptr_ref<Y>() throw() {
|
||||
return auto_ptr_ref<Y>(release());
|
||||
}
|
||||
template<typename Y> operator auto_ptr<Y>() throw() {
|
||||
return auto_ptr<Y>(release());
|
||||
}
|
||||
};
|
||||
|
||||
struct Base { Base() {} virtual ~Base() {} };
|
||||
struct Derived : Base { Derived() {}; };
|
||||
|
||||
auto_ptr<Derived> f() { auto_ptr<Derived> null(0); return null; }
|
||||
void g(auto_ptr<Derived>) { }
|
||||
void h(auto_ptr<Base>) { }
|
||||
|
||||
int main() {
|
||||
auto_ptr<Base> x(f());
|
||||
auto_ptr<Derived> y(f());
|
||||
x = y;
|
||||
g(f());
|
||||
h(f());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user