| 1 |
/* { dg-additional-options "-Wno-return-type" } */ |
| 2 |
|
| 3 |
typedef __SIZE_TYPE__ size_t; |
| 4 |
template<typename _Iterator, typename _Container> class __normal_iterator { |
| 5 |
public: |
| 6 |
const _Iterator& base() const; |
| 7 |
}; |
| 8 |
template<typename _BI1, typename _BI2> inline |
| 9 |
void copy_backward(_BI1 __first, _BI1 __last, _BI2 __result) { |
| 10 |
while (__first != __last) *--__result = *--__last; |
| 11 |
} |
| 12 |
template<typename _Tp> struct _Vector_base { |
| 13 |
struct _Vector_impl { _Tp* _M_finish; }; |
| 14 |
_Vector_impl _M_impl; |
| 15 |
}; |
| 16 |
template<typename _Tp > class vector : protected _Vector_base<_Tp> { |
| 17 |
typedef vector<_Tp> vector_type; |
| 18 |
typedef _Tp * pointer; |
| 19 |
typedef _Tp & reference; |
| 20 |
typedef __normal_iterator<pointer, vector_type> iterator; |
| 21 |
typedef size_t size_type; |
| 22 |
public: |
| 23 |
iterator end(); |
| 24 |
void resize(size_type __new_size) { insert(end(), __new_size); } |
| 25 |
reference operator[](size_type __n); |
| 26 |
void insert(iterator __position, size_type __n) |
| 27 |
{ |
| 28 |
pointer __old_finish(this->_M_impl._M_finish); |
| 29 |
copy_backward(__position.base(), __old_finish - __n, __old_finish); |
| 30 |
} |
| 31 |
}; |
| 32 |
struct A { |
| 33 |
virtual ~A (); |
| 34 |
void incRef (); |
| 35 |
void decRef (); |
| 36 |
}; |
| 37 |
struct C : public A { |
| 38 |
static C *alloc (); |
| 39 |
}; |
| 40 |
template <class T> struct B { |
| 41 |
B () : ptr (T::alloc ()) { } |
| 42 |
B (T *a_ptr) : ptr (a_ptr) { } |
| 43 |
~B () { decRef (); } |
| 44 |
B& operator= (const B<T>& a) { if (a.get () != this->get ()) { decRef (); |
| 45 |
incRef (); } } |
| 46 |
template<class U> operator B<U> () const { return B<U> (ptr); } |
| 47 |
T* operator-> () const { } |
| 48 |
T* get () const { return ptr; } |
| 49 |
void decRef () const { if (ptr != 0) ptr->decRef (); } |
| 50 |
void incRef () const { if (ptr != 0) ptr->incRef (); } |
| 51 |
T *ptr; |
| 52 |
}; |
| 53 |
struct D : public C { |
| 54 |
template <class T> inline void foo (const B<T> & x) { d.resize (1); d[0] = x; |
| 55 |
} |
| 56 |
vector<B <C> > d; |
| 57 |
}; |
| 58 |
struct E : public C { |
| 59 |
static E *alloc (); |
| 60 |
}; |
| 61 |
struct F : public D { |
| 62 |
static F *alloc (); |
| 63 |
}; |
| 64 |
void foo (vector<B<D> > & x) { |
| 65 |
for (int i = 0; i < 2; ++i) |
| 66 |
{ |
| 67 |
B<F> l; |
| 68 |
B<E> m; |
| 69 |
l->foo (m); |
| 70 |
} |
| 71 |
} |