2 // Test __cxa_vec routines
3 // Copyright (C) 2000 Free Software Foundation, Inc.
4 // Contributed by Nathan Sidwell 7 Apr 2000 <nathan@nathan@codesourcery.com>
6 #if defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100
13 static int ctor_count = 0;
14 static int dtor_count = 0;
15 static bool dtor_repeat = false;
17 // our pseudo ctors and dtors
18 static void ctor (void *)
25 static void dtor (void *)
36 // track new and delete
37 static int blocks = 0;
38 void *operator new[] (std::size_t size) throw (std::bad_alloc)
40 void *ptr = malloc (size);
43 throw std::bad_alloc ();
48 void operator delete[] (void *ptr) throw ()
58 // allocate and delete an array with no problems
61 static bool started = false;
66 std::set_terminate (test0);
68 ctor_count = dtor_count = 5;
74 void *ary = abi::__cxa_vec_new (5, 1, sizeof (std::size_t), ctor, dtor);
75 abi::__cxa_vec_delete (ary, 1, sizeof (std::size_t), dtor);
76 if (ctor_count || dtor_count || blocks)
91 // allocate and delete an array with exception on ctor
94 static bool started = false;
99 std::set_terminate (test1);
101 ctor_count = dtor_count = 5;
108 void *ary = abi::__cxa_vec_new (5, 1, sizeof (std::size_t), ctor, dtor);
113 // we expect to get here
114 if (ctor_count || dtor_count != 1 || blocks)
125 // allocate and delete an array with exception on dtor
128 static bool started = false;
133 std::set_terminate (test2);
134 ctor_count = dtor_count = 5;
141 void *ary = abi::__cxa_vec_new (5, 1, sizeof (std::size_t), ctor, dtor);
142 abi::__cxa_vec_delete (ary, 1, sizeof (std::size_t), dtor);
147 // we expect to get here
148 if (ctor_count || dtor_count != -2u || blocks)
159 // allocate an array with double exception on dtor
162 static bool started = false;
167 std::set_terminate (test3);
169 ctor_count = dtor_count = 5;
177 void *ary = abi::__cxa_vec_new (5, 1, sizeof (std::size_t), ctor, dtor);
178 abi::__cxa_vec_delete (ary, 1, sizeof (std::size_t), dtor);
183 // we do not expect to get here
189 // we expect to get here (via terminate)
190 if (ctor_count || dtor_count || blocks != 1)
197 // allocate an array with exception on ctor and exception in cleanup
200 static bool started = false;
205 std::set_terminate (test4);
207 ctor_count = dtor_count = 5;
215 void *ary = abi::__cxa_vec_new (5, 1, sizeof (std::size_t), ctor, dtor);
220 // we do not expect to get here
226 // we expect to get here (via terminate)
227 if (ctor_count || dtor_count != -1u || blocks != 1)
234 static void (*tests[])() =
250 for (ix = 0; tests[ix]; ix++)
252 if (n = setjmp (jump))
256 printf ("test %d failed %d\n", ix, n);