1 /* { dg-do compile } */
2 /* { dg-additional-options "-Wno-return-type" } */
4 void *fastMalloc (int n);
5 void fastFree (void *p);
6 template <class T> struct C
8 void deref () { delete static_cast <T *>(this); }
13 D (T *ptr) : m_ptr (ptr) { }
14 ~D () { if (T * ptr = m_ptr) ptr->deref (); }
15 T *operator-> () const;
17 typedef T *UnspecifiedBoolType;
18 operator UnspecifiedBoolType () const;
20 template <typename T> struct E
22 static void destruct (T * begin, T * end)
24 for (T * cur = begin; cur != end; ++cur)
28 template <typename T> class F;
29 template <typename T> struct G
31 static void destruct (T * begin, T * end)
33 E <T>::destruct (begin, end);
35 static void uninitializedFill (T * dst, T * dstEnd, const T & val)
37 F<T>::uninitializedFill (dst, dstEnd, val);
40 template <typename T> struct H
42 void allocateBuffer (int newCapacity)
44 m_buffer = static_cast <T *>(fastMalloc (newCapacity * sizeof (T)));
46 void deallocateBuffer (T * bufferToDeallocate)
48 if (m_buffer == bufferToDeallocate)
49 fastFree (bufferToDeallocate);
52 int capacity () const { }
55 template <typename T, int cap> class I;
56 template <typename T> struct I <T, 0> : H <T>
58 I (int capacity) { allocateBuffer (capacity); }
59 ~I () { this->deallocateBuffer (buffer ()); }
60 using H <T>::allocateBuffer;
61 H <T>::buffer; // { dg-warning "deprecated" }
63 template <typename T, int cap = 0> struct J
66 ~J () { if (m_size) shrink (0); }
68 int capacity () const { m_buffer.capacity (); }
69 T & operator[](int i) { }
71 iterator end () { return begin () + m_size; }
72 void shrink (int size);
73 template <typename U> void append (const U &);
77 template <typename T, int cap>
78 J <T, cap>::J (const J & other) : m_buffer (other.capacity ())
81 template <typename T, int cap>
82 void J <T, cap>::shrink (int size)
84 G <T>::destruct (begin () + size, end ());
87 struct A : public C <A>
91 virtual A *firstChild () const;
92 virtual A *nextSibling () const;
93 virtual const B & children (int length);
97 A::children (int length)
99 for (D <A> obj = firstChild (); obj; obj = obj->nextSibling ())
101 B children = obj->children (2);
102 for (unsigned i = 0; i <length; ++i)
103 m_children.append (children[i]);