1 // Test __cxa_vec routines
2 // Copyright (C) 2000 Free Software Foundation, Inc.
3 // Contributed by Nathan Sidwell 7 Apr 2000 <nathan@nathan@codesourcery.com>
5 #if defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100
12 static int ctor_count = 0;
13 static int dtor_count = 0;
14 static bool dtor_repeat = false;
16 // our pseudo ctors and dtors
17 static void ctor (void *)
24 static void dtor (void *)
35 // track new and delete
36 static int blocks = 0;
37 void *operator new[] (std::size_t size) throw (std::bad_alloc)
39 void *ptr = malloc (size);
42 throw std::bad_alloc ();
47 void operator delete[] (void *ptr) throw ()
57 // allocate and delete an array with no problems
60 static bool started = false;
65 std::set_terminate (test0);
67 ctor_count = dtor_count = 5;
73 void *ary = abi::__cxa_vec_new (5, 1, sizeof (std::size_t), ctor, dtor);
74 abi::__cxa_vec_delete (ary, 1, sizeof (std::size_t), dtor);
75 if (ctor_count || dtor_count || blocks)
90 // allocate and delete an array with exception on ctor
93 static bool started = false;
98 std::set_terminate (test1);
100 ctor_count = dtor_count = 5;
107 void *ary = abi::__cxa_vec_new (5, 1, sizeof (std::size_t), ctor, dtor);
112 // we expect to get here
113 if (ctor_count || dtor_count != 1 || blocks)
124 // allocate and delete an array with exception on dtor
127 static bool started = false;
132 std::set_terminate (test2);
133 ctor_count = dtor_count = 5;
140 void *ary = abi::__cxa_vec_new (5, 1, sizeof (std::size_t), ctor, dtor);
141 abi::__cxa_vec_delete (ary, 1, sizeof (std::size_t), dtor);
146 // we expect to get here
147 if (ctor_count || dtor_count != -2u || blocks)
158 // allocate an array with double exception on dtor
161 static bool started = false;
166 std::set_terminate (test3);
168 ctor_count = dtor_count = 5;
176 void *ary = abi::__cxa_vec_new (5, 1, sizeof (std::size_t), ctor, dtor);
177 abi::__cxa_vec_delete (ary, 1, sizeof (std::size_t), dtor);
182 // we do not expect to get here
188 // we expect to get here (via terminate)
189 if (ctor_count || dtor_count || blocks != 1)
196 // allocate an array with exception on ctor and exception in cleanup
199 static bool started = false;
204 std::set_terminate (test4);
206 ctor_count = dtor_count = 5;
214 void *ary = abi::__cxa_vec_new (5, 1, sizeof (std::size_t), ctor, dtor);
219 // we do not expect to get here
225 // we expect to get here (via terminate)
226 if (ctor_count || dtor_count != -1u || blocks != 1)
233 static void (*tests[])() =
249 for (ix = 0; tests[ix]; ix++)
251 if (n = setjmp (jump))
255 printf ("test %d failed %d\n", ix, n);