1 /* { dg-do compile } */
3 void *fastMalloc (int n);
4 void fastFree (void *p);
5 template <class T> struct C
7 void deref () { delete static_cast <T *>(this); }
12 D (T *ptr) : m_ptr (ptr) { }
13 ~D () { if (T * ptr = m_ptr) ptr->deref (); }
14 T *operator-> () const;
16 typedef T *UnspecifiedBoolType;
17 operator UnspecifiedBoolType () const;
19 template <typename T> struct E
21 static void destruct (T * begin, T * end)
23 for (T * cur = begin; cur != end; ++cur)
27 template <typename T> class F;
28 template <typename T> struct G
30 static void destruct (T * begin, T * end)
32 E <T>::destruct (begin, end);
34 static void uninitializedFill (T * dst, T * dstEnd, const T & val)
36 F<T>::uninitializedFill (dst, dstEnd, val);
39 template <typename T> struct H
41 void allocateBuffer (int newCapacity)
43 m_buffer = static_cast <T *>(fastMalloc (newCapacity * sizeof (T)));
45 void deallocateBuffer (T * bufferToDeallocate)
47 if (m_buffer == bufferToDeallocate)
48 fastFree (bufferToDeallocate);
51 int capacity () const { }
54 template <typename T, int cap> class I;
55 template <typename T> struct I <T, 0> : H <T>
57 I (int capacity) { allocateBuffer (capacity); }
58 ~I () { this->deallocateBuffer (buffer ()); }
59 using H <T>::allocateBuffer;
60 H <T>::buffer; // { dg-warning "deprecated" }
62 template <typename T, int cap = 0> struct J
65 ~J () { if (m_size) shrink (0); }
67 int capacity () const { m_buffer.capacity (); }
68 T & operator[](int i) { }
70 iterator end () { return begin () + m_size; }
71 void shrink (int size);
72 template <typename U> void append (const U &);
76 template <typename T, int cap>
77 J <T, cap>::J (const J & other) : m_buffer (other.capacity ())
80 template <typename T, int cap>
81 void J <T, cap>::shrink (int size)
83 G <T>::destruct (begin () + size, end ());
86 struct A : public C <A>
90 virtual A *firstChild () const;
91 virtual A *nextSibling () const;
92 virtual const B & children (int length);
96 A::children (int length)
98 for (D <A> obj = firstChild (); obj; obj = obj->nextSibling ())
100 B children = obj->children (2);
101 for (unsigned i = 0; i <length; ++i)
102 m_children.append (children[i]);