1 // This test fails on VxWorks in kernel mode because it depends on the
2 // library version of "::operator new[]" calling the "::operator new"
3 // defined in this module. This doesn't work because the library version
4 // of "::operator new[]" is built into the kernel itself; library relocations
5 // are resolved when the kernel is linked.
6 // { dg-do run { xfail { powerpc-ibm-aix* || vxworks_kernel } } }
7 // { dg-options "-flat_namespace" { target *-*-darwin[67]* } }
8 // Test __cxa_vec routines
9 // Copyright (C) 2000, 2005 Free Software Foundation, Inc.
10 // Contributed by Nathan Sidwell 7 Apr 2000 <nathan@nathan@codesourcery.com>
12 #if defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100
19 static int ctor_count = 0;
20 static int dtor_count = 0;
21 static bool dtor_repeat = false;
23 // Allocate enough padding to hold an array cookie.
27 #define padding (sizeof (std::size_t))
30 // our pseudo ctors and dtors
31 static abi::__cxa_cdtor_return_type ctor (void *x)
41 static abi::__cxa_cdtor_return_type dtor (void *x)
55 // track new and delete
56 static int blocks = 0;
57 void *operator new[] (std::size_t size) throw (std::bad_alloc)
59 void *ptr = malloc (size);
62 throw std::bad_alloc ();
67 void operator delete[] (void *ptr) throw ()
77 // allocate and delete an array with no problems
80 static bool started = false;
85 std::set_terminate (test0);
87 ctor_count = dtor_count = 5;
93 void *ary = abi::__cxa_vec_new (5, 1, padding, ctor, dtor);
94 abi::__cxa_vec_delete (ary, 1, padding, dtor);
95 if (ctor_count || dtor_count || blocks)
110 // allocate and delete an array with exception on ctor
113 static bool started = false;
118 std::set_terminate (test1);
120 ctor_count = dtor_count = 5;
127 void *ary = abi::__cxa_vec_new (5, 1, padding, ctor, dtor);
132 // we expect to get here
133 if (ctor_count || dtor_count != 1 || blocks)
144 // allocate and delete an array with exception on dtor
147 static bool started = false;
152 std::set_terminate (test2);
153 ctor_count = dtor_count = 5;
160 void *ary = abi::__cxa_vec_new (5, 1, padding, ctor, dtor);
161 abi::__cxa_vec_delete (ary, 1, padding, dtor);
166 // we expect to get here
167 if (ctor_count || dtor_count != -2u || blocks)
178 // allocate an array with double exception on dtor
181 static bool started = false;
186 std::set_terminate (test3);
188 ctor_count = dtor_count = 5;
196 void *ary = abi::__cxa_vec_new (5, 1, padding, ctor, dtor);
197 abi::__cxa_vec_delete (ary, 1, padding, dtor);
202 // we do not expect to get here
208 // we expect to get here (via terminate)
209 if (ctor_count || dtor_count || blocks != 1)
216 // allocate an array with exception on ctor and exception in cleanup
219 static bool started = false;
224 std::set_terminate (test4);
226 ctor_count = dtor_count = 5;
234 void *ary = abi::__cxa_vec_new (5, 1, padding, ctor, dtor);
239 // we do not expect to get here
245 // we expect to get here (via terminate)
246 if (ctor_count || dtor_count != -1u || blocks != 1)
253 static void (*tests[])() =
269 for (ix = 0; tests[ix]; ix++)
271 if (n = setjmp (jump))
275 printf ("test %d failed %d\n", ix, n);