Merge -r 127928:132243 from trunk
[official-gcc.git] / gcc / testsuite / g++.dg / torture / pr34641.C
blob9e4f2662e7845d51fd2ad07117e97cd00ceef4c1
1 // { dg-do compile }
2 // { dg-require-effective-target fpic }
3 // { dg-require-visibility "" }
4 // { dg-options "-fPIC" }
7 typedef __SIZE_TYPE__ size_t;
8 extern "C" void *
9 malloc (size_t __size)
10 throw () __attribute__ ((__malloc__));
11      namespace std __attribute__ ((__visibility__ ("default")))
13   using::size_t;
15 inline void *operator
16 new (std::size_t, void *__p)
17 throw ()
19   return __p;
21 template < class _T1, class _T2 > struct pair
23   _T1 first;
24   _T2 second;
25     pair (const _T1 & __a, const _T2 & __b):first (__a), second (__b)
26   {
27   }
28   template < class _U1, class _U2 >
29     pair (const pair < _U1, _U2 > &__p):first (__p.first), second (__p.second)
30   {
31   }
34 template < class _T1, class _T2 >
35   inline pair < _T1, _T2 > make_pair (_T1 __x, _T2 __y)
37   return pair < _T1, _T2 > (__x, __y);
39 template < typename _Tp > inline const _Tp &
40 max (const _Tp & __a, const _Tp & __b)
43 typedef unsigned short int uint16_t;
44 typedef unsigned long int uintptr_t;
45 typedef uint16_t UChar;
46 namespace std __attribute__ ((__visibility__ ("default")))
48   struct __numeric_limits_base
49   {
50   };
51   template < typename _Tp > struct numeric_limits:public __numeric_limits_base
52   {
53     static _Tp max () throw ()
54     {
55     }
56   };
59 template < typename T > class VectorBufferBase
61 public:
62   void allocateBuffer (size_t newCapacity)
63   {
64     if (newCapacity > std::numeric_limits < size_t >::max () / sizeof (T))
65       *(int *) (uintptr_t) 0xbbadbeef = 0;
66   }
69 template < typename T, size_t inlineCapacity > class VectorBuffer;
70 template < typename T > class VectorBuffer < T, 0 >:private VectorBufferBase <
71   T >
73   typedef VectorBufferBase < T > Base;
74   using Base::allocateBuffer;
77 template < typename T, size_t inlineCapacity = 0 > class Vector
79   typedef VectorBuffer < T, inlineCapacity > Impl;
80 public:
81   typedef T *iterator;
82   size_t size () const
83   {
84     return m_size;
85   }
86   size_t capacity () const
87   {
88   }
89   iterator begin ()
90   {
91   }
92   iterator end ()
93   {
94     return begin () + m_size;
95   }
96   void shrink (size_t size);
97   void reserveCapacity (size_t newCapacity);
98   void clear ()
99   {
100     shrink (0);
101   }
102   template < typename U > void append (const U &);
103   void expandCapacity (size_t newMinCapacity);
104   template < typename U > U * expandCapacity (size_t newMinCapacity, U *);
105   size_t m_size;
106   Impl m_impl;
108 template < typename T, size_t inlineCapacity >
109   void Vector < T, inlineCapacity >::expandCapacity (size_t newMinCapacity)
111   reserveCapacity (max
112                    (newMinCapacity,
113                     max (static_cast < size_t > (16),
114                          capacity () + capacity () / 4 + 1)));
117 template < typename T, size_t inlineCapacity >
118   template < typename U >
119   inline U * Vector < T,
120   inlineCapacity >::expandCapacity (size_t newMinCapacity, U * ptr)
122   expandCapacity (newMinCapacity);
124 template < typename T, size_t inlineCapacity >
125   void Vector < T, inlineCapacity >::reserveCapacity (size_t newCapacity)
127   m_impl.allocateBuffer (newCapacity);
129 template < typename T, size_t inlineCapacity >
130   template < typename U >
131   inline void Vector < T, inlineCapacity >::append (const U & val)
133   const U *ptr = &val;
134   if (size () == capacity ())
135     ptr = expandCapacity (size () + 1, ptr);
136   new (end ())T (*ptr);
139 class Range;
140 class TextIterator
142 public:
143   explicit TextIterator (const Range *,
144                          bool emitCharactersBetweenAllVisiblePositions =
145                          false);
146   bool atEnd () const
147   {
148   }
149   void advance ();
150   int length () const
151   {
152   }
154 UChar *
155 plainTextToMallocAllocatedBuffer (const Range * r, unsigned &bufferLength)
157   static const unsigned cMaxSegmentSize = 1 << 16;
158   typedef pair < UChar *, unsigned >TextSegment;
159   Vector < TextSegment > *textSegments = 0;
160   Vector < UChar > textBuffer;
161   for (TextIterator it (r); !it.atEnd (); it.advance ())
162     {
163       if (textBuffer.size ()
164           && textBuffer.size () + it.length () > cMaxSegmentSize)
165         {
166           UChar *newSegmentBuffer =
167             static_cast <
168             UChar * >(malloc (textBuffer.size () * sizeof (UChar)));
169           if (!textSegments)
170             textSegments = new Vector < TextSegment >;
171           textSegments->
172             append (make_pair (newSegmentBuffer, textBuffer.size ()));
173           textBuffer.clear ();
174         }
175     }