1 // { dg-do run { xfail powerpc-ibm-aix* } }
2 // { dg-options "-flat_namespace" { target *-*-darwin[67]* } }
3 // Test __cxa_vec routines
4 // Copyright (C) 2000, 2005 Free Software Foundation, Inc.
5 // Contributed by Nathan Sidwell 7 Apr 2000 <nathan@nathan@codesourcery.com>
7 #if defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100
14 static int ctor_count = 0;
15 static int dtor_count = 0;
16 static bool dtor_repeat = false;
18 // Allocate enough padding to hold an array cookie.
22 #define padding (sizeof (std::size_t))
25 // our pseudo ctors and dtors
26 static abi::__cxa_cdtor_return_type ctor (void *x)
36 static abi::__cxa_cdtor_return_type dtor (void *x)
50 // track new and delete
51 static int blocks = 0;
52 void *operator new[] (std::size_t size) throw (std::bad_alloc)
54 void *ptr = malloc (size);
57 throw std::bad_alloc ();
62 void operator delete[] (void *ptr) throw ()
72 // allocate and delete an array with no problems
75 static bool started = false;
80 std::set_terminate (test0);
82 ctor_count = dtor_count = 5;
88 void *ary = abi::__cxa_vec_new (5, 1, padding, ctor, dtor);
89 abi::__cxa_vec_delete (ary, 1, padding, dtor);
90 if (ctor_count || dtor_count || blocks)
105 // allocate and delete an array with exception on ctor
108 static bool started = false;
113 std::set_terminate (test1);
115 ctor_count = dtor_count = 5;
122 void *ary = abi::__cxa_vec_new (5, 1, padding, ctor, dtor);
127 // we expect to get here
128 if (ctor_count || dtor_count != 1 || blocks)
139 // allocate and delete an array with exception on dtor
142 static bool started = false;
147 std::set_terminate (test2);
148 ctor_count = dtor_count = 5;
155 void *ary = abi::__cxa_vec_new (5, 1, padding, ctor, dtor);
156 abi::__cxa_vec_delete (ary, 1, padding, dtor);
161 // we expect to get here
162 if (ctor_count || dtor_count != -2u || blocks)
173 // allocate an array with double exception on dtor
176 static bool started = false;
181 std::set_terminate (test3);
183 ctor_count = dtor_count = 5;
191 void *ary = abi::__cxa_vec_new (5, 1, padding, ctor, dtor);
192 abi::__cxa_vec_delete (ary, 1, padding, dtor);
197 // we do not expect to get here
203 // we expect to get here (via terminate)
204 if (ctor_count || dtor_count || blocks != 1)
211 // allocate an array with exception on ctor and exception in cleanup
214 static bool started = false;
219 std::set_terminate (test4);
221 ctor_count = dtor_count = 5;
229 void *ary = abi::__cxa_vec_new (5, 1, padding, ctor, dtor);
234 // we do not expect to get here
240 // we expect to get here (via terminate)
241 if (ctor_count || dtor_count != -1u || blocks != 1)
248 static void (*tests[])() =
264 for (ix = 0; tests[ix]; ix++)
266 if (n = setjmp (jump))
270 printf ("test %d failed %d\n", ix, n);