[AArch64] Fix SVE testsuite failures for ILP32 (PR 83846)
[official-gcc.git] / gcc / testsuite / g++.dg / torture / pr39362.C
blob6599fdd70c0374f170be53ef65bb55cb1ff2040a
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); }
9 };
10 template <typename T>
11 struct D
13   D (T *ptr) : m_ptr (ptr) { }
14   ~D () { if (T * ptr = m_ptr) ptr->deref (); }
15   T *operator-> () const;
16   T *m_ptr;
17   typedef T *UnspecifiedBoolType;
18   operator UnspecifiedBoolType () const;
20 template <typename T> struct E
22   static void destruct (T * begin, T * end)
23     {
24       for (T * cur = begin; cur != end; ++cur)
25         cur->~T ();
26     }
28 template <typename T> class F;
29 template <typename T> struct G
31   static void destruct (T * begin, T * end)
32     {
33       E <T>::destruct (begin, end);
34     }
35   static void uninitializedFill (T * dst, T * dstEnd, const T & val)
36     {
37       F<T>::uninitializedFill (dst, dstEnd, val);
38     }
40 template <typename T> struct H
42   void allocateBuffer (int newCapacity)
43     {
44       m_buffer = static_cast <T *>(fastMalloc (newCapacity * sizeof (T)));
45     }
46   void deallocateBuffer (T * bufferToDeallocate)
47     {
48       if (m_buffer == bufferToDeallocate)
49         fastFree (bufferToDeallocate);
50     }
51   T *buffer () { }
52   int capacity () const { }
53   T *m_buffer;
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
65   typedef T *iterator;
66   ~J () { if (m_size) shrink (0); }
67   J (const J &);
68   int capacity () const { m_buffer.capacity (); }
69   T & operator[](int i) { }
70   iterator begin () { }
71   iterator end () { return begin () + m_size; }
72   void shrink (int size);
73   template <typename U> void append (const U &);
74   int m_size;
75   I <T, cap> m_buffer;
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 ());
85   m_size = size;
87 struct A : public C <A>
89   virtual ~A ();
90   typedef J <D <A> > B;
91   virtual A *firstChild () const;
92   virtual A *nextSibling () const;
93   virtual const B & children (int length);
94   B m_children;
96 const A::B &
97 A::children (int length)
99   for (D <A> obj = firstChild (); obj; obj = obj->nextSibling ())
100     {
101       B children = obj->children (2);
102       for (unsigned i = 0; i <length; ++i)
103         m_children.append (children[i]);
104     }