xref: /aosp_15_r20/external/libcxxabi/test/test_vector1.pass.cpp (revision c05d8e5dc3e10f6ce4317e8bc22cc4a25f55fa94)
1*c05d8e5dSAndroid Build Coastguard Worker //===---------------------------- test_vector.cpp -------------------------===//
2*c05d8e5dSAndroid Build Coastguard Worker //
3*c05d8e5dSAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*c05d8e5dSAndroid Build Coastguard Worker //
5*c05d8e5dSAndroid Build Coastguard Worker // This file is dual licensed under the MIT and the University of Illinois Open
6*c05d8e5dSAndroid Build Coastguard Worker // Source Licenses. See LICENSE.TXT for details.
7*c05d8e5dSAndroid Build Coastguard Worker //
8*c05d8e5dSAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*c05d8e5dSAndroid Build Coastguard Worker 
10*c05d8e5dSAndroid Build Coastguard Worker #include "cxxabi.h"
11*c05d8e5dSAndroid Build Coastguard Worker 
12*c05d8e5dSAndroid Build Coastguard Worker #include <iostream>
13*c05d8e5dSAndroid Build Coastguard Worker #include <cstdlib>
14*c05d8e5dSAndroid Build Coastguard Worker #include <cassert>
15*c05d8e5dSAndroid Build Coastguard Worker 
16*c05d8e5dSAndroid Build Coastguard Worker //  Wrapper routines
my_alloc2(size_t sz)17*c05d8e5dSAndroid Build Coastguard Worker void *my_alloc2 ( size_t sz ) {
18*c05d8e5dSAndroid Build Coastguard Worker     void *p = std::malloc ( sz );
19*c05d8e5dSAndroid Build Coastguard Worker //  std::printf ( "Allocated %ld bytes at %lx\n", sz, (unsigned long) p );
20*c05d8e5dSAndroid Build Coastguard Worker     return p;
21*c05d8e5dSAndroid Build Coastguard Worker     }
22*c05d8e5dSAndroid Build Coastguard Worker 
my_dealloc2(void * p)23*c05d8e5dSAndroid Build Coastguard Worker void my_dealloc2 ( void *p ) {
24*c05d8e5dSAndroid Build Coastguard Worker //  std::printf ( "Freeing %lx\n", (unsigned long) p );
25*c05d8e5dSAndroid Build Coastguard Worker     std::free ( p );
26*c05d8e5dSAndroid Build Coastguard Worker     }
27*c05d8e5dSAndroid Build Coastguard Worker 
my_dealloc3(void * p,size_t)28*c05d8e5dSAndroid Build Coastguard Worker void my_dealloc3 ( void *p, size_t ) {
29*c05d8e5dSAndroid Build Coastguard Worker //  std::printf ( "Freeing %lx (size %ld)\n", (unsigned long) p, sz );
30*c05d8e5dSAndroid Build Coastguard Worker     std::free ( p );
31*c05d8e5dSAndroid Build Coastguard Worker     }
32*c05d8e5dSAndroid Build Coastguard Worker 
my_construct(void *)33*c05d8e5dSAndroid Build Coastguard Worker void my_construct ( void * ) {
34*c05d8e5dSAndroid Build Coastguard Worker //  std::printf ( "Constructing %lx\n", (unsigned long) p );
35*c05d8e5dSAndroid Build Coastguard Worker     }
36*c05d8e5dSAndroid Build Coastguard Worker 
my_destruct(void *)37*c05d8e5dSAndroid Build Coastguard Worker void my_destruct  ( void * ) {
38*c05d8e5dSAndroid Build Coastguard Worker //  std::printf ( "Destructing  %lx\n", (unsigned long) p );
39*c05d8e5dSAndroid Build Coastguard Worker     }
40*c05d8e5dSAndroid Build Coastguard Worker 
41*c05d8e5dSAndroid Build Coastguard Worker int gCounter;
count_construct(void *)42*c05d8e5dSAndroid Build Coastguard Worker void count_construct ( void * ) { ++gCounter; }
count_destruct(void *)43*c05d8e5dSAndroid Build Coastguard Worker void count_destruct  ( void * ) { --gCounter; }
44*c05d8e5dSAndroid Build Coastguard Worker 
45*c05d8e5dSAndroid Build Coastguard Worker 
46*c05d8e5dSAndroid Build Coastguard Worker int gConstructorCounter;
47*c05d8e5dSAndroid Build Coastguard Worker int gConstructorThrowTarget;
48*c05d8e5dSAndroid Build Coastguard Worker int gDestructorCounter;
49*c05d8e5dSAndroid Build Coastguard Worker int gDestructorThrowTarget;
throw_construct(void *)50*c05d8e5dSAndroid Build Coastguard Worker void throw_construct ( void * ) {
51*c05d8e5dSAndroid Build Coastguard Worker #ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
52*c05d8e5dSAndroid Build Coastguard Worker     if ( gConstructorCounter   == gConstructorThrowTarget )
53*c05d8e5dSAndroid Build Coastguard Worker         throw 1;
54*c05d8e5dSAndroid Build Coastguard Worker     ++gConstructorCounter;
55*c05d8e5dSAndroid Build Coastguard Worker #endif
56*c05d8e5dSAndroid Build Coastguard Worker }
throw_destruct(void *)57*c05d8e5dSAndroid Build Coastguard Worker void throw_destruct  ( void * ) {
58*c05d8e5dSAndroid Build Coastguard Worker #ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
59*c05d8e5dSAndroid Build Coastguard Worker     if ( ++gDestructorCounter  == gDestructorThrowTarget  )
60*c05d8e5dSAndroid Build Coastguard Worker         throw 2;
61*c05d8e5dSAndroid Build Coastguard Worker #endif
62*c05d8e5dSAndroid Build Coastguard Worker }
63*c05d8e5dSAndroid Build Coastguard Worker 
64*c05d8e5dSAndroid Build Coastguard Worker #if __cplusplus >= 201103L
65*c05d8e5dSAndroid Build Coastguard Worker #   define CAN_THROW noexcept(false)
66*c05d8e5dSAndroid Build Coastguard Worker #else
67*c05d8e5dSAndroid Build Coastguard Worker #   define CAN_THROW
68*c05d8e5dSAndroid Build Coastguard Worker #endif
69*c05d8e5dSAndroid Build Coastguard Worker 
70*c05d8e5dSAndroid Build Coastguard Worker struct vec_on_stack {
71*c05d8e5dSAndroid Build Coastguard Worker     void *storage;
vec_on_stackvec_on_stack72*c05d8e5dSAndroid Build Coastguard Worker     vec_on_stack () : storage ( __cxxabiv1::__cxa_vec_new    (            10, 40, 8, throw_construct, throw_destruct )) {}
~vec_on_stackvec_on_stack73*c05d8e5dSAndroid Build Coastguard Worker     ~vec_on_stack () CAN_THROW {__cxxabiv1::__cxa_vec_delete ( storage,       40, 8,                  throw_destruct );  }
74*c05d8e5dSAndroid Build Coastguard Worker     };
75*c05d8e5dSAndroid Build Coastguard Worker 
76*c05d8e5dSAndroid Build Coastguard Worker //  Test calls with empty constructors and destructors
test_empty()77*c05d8e5dSAndroid Build Coastguard Worker int test_empty ( ) {
78*c05d8e5dSAndroid Build Coastguard Worker     void *one, *two, *three;
79*c05d8e5dSAndroid Build Coastguard Worker 
80*c05d8e5dSAndroid Build Coastguard Worker //  Try with no padding and no con/destructors
81*c05d8e5dSAndroid Build Coastguard Worker     one     = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, NULL, NULL );
82*c05d8e5dSAndroid Build Coastguard Worker     two     = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, NULL, NULL, my_alloc2, my_dealloc2 );
83*c05d8e5dSAndroid Build Coastguard Worker     three   = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, NULL, NULL, my_alloc2, my_dealloc3 );
84*c05d8e5dSAndroid Build Coastguard Worker 
85*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete ( one,       40, 0, NULL );
86*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete2( two,       40, 0, NULL, my_dealloc2 );
87*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete3( three,     40, 0, NULL, my_dealloc3 );
88*c05d8e5dSAndroid Build Coastguard Worker 
89*c05d8e5dSAndroid Build Coastguard Worker //  Try with no padding
90*c05d8e5dSAndroid Build Coastguard Worker     one     = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, my_construct, my_destruct );
91*c05d8e5dSAndroid Build Coastguard Worker     two     = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, my_construct, my_destruct, my_alloc2, my_dealloc2 );
92*c05d8e5dSAndroid Build Coastguard Worker     three   = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, my_construct, my_destruct, my_alloc2, my_dealloc3 );
93*c05d8e5dSAndroid Build Coastguard Worker 
94*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete ( one,       40, 0, my_destruct );
95*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete2( two,       40, 0, my_destruct, my_dealloc2 );
96*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete3( three,     40, 0, my_destruct, my_dealloc3 );
97*c05d8e5dSAndroid Build Coastguard Worker 
98*c05d8e5dSAndroid Build Coastguard Worker //  Padding and no con/destructors
99*c05d8e5dSAndroid Build Coastguard Worker     one     = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, NULL, NULL );
100*c05d8e5dSAndroid Build Coastguard Worker     two     = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, NULL, NULL, my_alloc2, my_dealloc2 );
101*c05d8e5dSAndroid Build Coastguard Worker     three   = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, NULL, NULL, my_alloc2, my_dealloc3 );
102*c05d8e5dSAndroid Build Coastguard Worker 
103*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete ( one,       40, 8, NULL );
104*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete2( two,       40, 8, NULL, my_dealloc2 );
105*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete3( three,     40, 8, NULL, my_dealloc3 );
106*c05d8e5dSAndroid Build Coastguard Worker 
107*c05d8e5dSAndroid Build Coastguard Worker //  Padding with con/destructors
108*c05d8e5dSAndroid Build Coastguard Worker     one     = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, my_construct, my_destruct );
109*c05d8e5dSAndroid Build Coastguard Worker     two     = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, my_construct, my_destruct, my_alloc2, my_dealloc2 );
110*c05d8e5dSAndroid Build Coastguard Worker     three   = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, my_construct, my_destruct, my_alloc2, my_dealloc3 );
111*c05d8e5dSAndroid Build Coastguard Worker 
112*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete ( one,       40, 8, my_destruct );
113*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete2( two,       40, 8, my_destruct, my_dealloc2 );
114*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete3( three,     40, 8, my_destruct, my_dealloc3 );
115*c05d8e5dSAndroid Build Coastguard Worker 
116*c05d8e5dSAndroid Build Coastguard Worker     return 0;
117*c05d8e5dSAndroid Build Coastguard Worker     }
118*c05d8e5dSAndroid Build Coastguard Worker 
119*c05d8e5dSAndroid Build Coastguard Worker //  Make sure the constructors and destructors are matched
test_counted()120*c05d8e5dSAndroid Build Coastguard Worker int test_counted ( ) {
121*c05d8e5dSAndroid Build Coastguard Worker     int retVal = 0;
122*c05d8e5dSAndroid Build Coastguard Worker     void *one, *two, *three;
123*c05d8e5dSAndroid Build Coastguard Worker 
124*c05d8e5dSAndroid Build Coastguard Worker //  Try with no padding
125*c05d8e5dSAndroid Build Coastguard Worker     gCounter = 0;
126*c05d8e5dSAndroid Build Coastguard Worker     one     = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, count_construct, count_destruct );
127*c05d8e5dSAndroid Build Coastguard Worker     two     = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, count_construct, count_destruct, my_alloc2, my_dealloc2 );
128*c05d8e5dSAndroid Build Coastguard Worker     three   = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, count_construct, count_destruct, my_alloc2, my_dealloc3 );
129*c05d8e5dSAndroid Build Coastguard Worker 
130*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete ( one,       40, 0, count_destruct );
131*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete2( two,       40, 0, count_destruct, my_dealloc2 );
132*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete3( three,     40, 0, count_destruct, my_dealloc3 );
133*c05d8e5dSAndroid Build Coastguard Worker 
134*c05d8e5dSAndroid Build Coastguard Worker //  Since there was no padding, the # of elements in the array are not stored
135*c05d8e5dSAndroid Build Coastguard Worker //  and the destructors are not called.
136*c05d8e5dSAndroid Build Coastguard Worker     if ( gCounter != 30 ) {
137*c05d8e5dSAndroid Build Coastguard Worker         std::cerr << "Mismatched Constructor/Destructor calls (1)" << std::endl;
138*c05d8e5dSAndroid Build Coastguard Worker         std::cerr << "  Expected 30, got " << gCounter << std::endl;
139*c05d8e5dSAndroid Build Coastguard Worker         retVal = 1;
140*c05d8e5dSAndroid Build Coastguard Worker         }
141*c05d8e5dSAndroid Build Coastguard Worker 
142*c05d8e5dSAndroid Build Coastguard Worker     gCounter = 0;
143*c05d8e5dSAndroid Build Coastguard Worker     one     = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, count_construct, count_destruct );
144*c05d8e5dSAndroid Build Coastguard Worker     two     = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, count_construct, count_destruct, my_alloc2, my_dealloc2 );
145*c05d8e5dSAndroid Build Coastguard Worker     three   = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, count_construct, count_destruct, my_alloc2, my_dealloc3 );
146*c05d8e5dSAndroid Build Coastguard Worker 
147*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete ( one,       40, 8, count_destruct );
148*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete2( two,       40, 8, count_destruct, my_dealloc2 );
149*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete3( three,     40, 8, count_destruct, my_dealloc3 );
150*c05d8e5dSAndroid Build Coastguard Worker 
151*c05d8e5dSAndroid Build Coastguard Worker     if ( gCounter != 0 ) {
152*c05d8e5dSAndroid Build Coastguard Worker         std::cerr << "Mismatched Constructor/Destructor calls (2)" << std::endl;
153*c05d8e5dSAndroid Build Coastguard Worker         std::cerr << "  Expected 0, got " << gCounter << std::endl;
154*c05d8e5dSAndroid Build Coastguard Worker         retVal = 1;
155*c05d8e5dSAndroid Build Coastguard Worker         }
156*c05d8e5dSAndroid Build Coastguard Worker 
157*c05d8e5dSAndroid Build Coastguard Worker     return retVal;
158*c05d8e5dSAndroid Build Coastguard Worker     }
159*c05d8e5dSAndroid Build Coastguard Worker 
160*c05d8e5dSAndroid Build Coastguard Worker #ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
161*c05d8e5dSAndroid Build Coastguard Worker //  Make sure the constructors and destructors are matched
test_exception_in_constructor()162*c05d8e5dSAndroid Build Coastguard Worker int test_exception_in_constructor ( ) {
163*c05d8e5dSAndroid Build Coastguard Worker     int retVal = 0;
164*c05d8e5dSAndroid Build Coastguard Worker     void *one, *two, *three;
165*c05d8e5dSAndroid Build Coastguard Worker 
166*c05d8e5dSAndroid Build Coastguard Worker //  Try with no padding
167*c05d8e5dSAndroid Build Coastguard Worker     gConstructorCounter = gDestructorCounter = 0;
168*c05d8e5dSAndroid Build Coastguard Worker     gConstructorThrowTarget = 15;
169*c05d8e5dSAndroid Build Coastguard Worker     gDestructorThrowTarget  = -1;
170*c05d8e5dSAndroid Build Coastguard Worker     try {
171*c05d8e5dSAndroid Build Coastguard Worker         one = two = three = NULL;
172*c05d8e5dSAndroid Build Coastguard Worker         one     = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, throw_construct, throw_destruct );
173*c05d8e5dSAndroid Build Coastguard Worker         two     = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, throw_construct, throw_destruct, my_alloc2, my_dealloc2 );
174*c05d8e5dSAndroid Build Coastguard Worker         three   = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, throw_construct, throw_destruct, my_alloc2, my_dealloc3 );
175*c05d8e5dSAndroid Build Coastguard Worker         }
176*c05d8e5dSAndroid Build Coastguard Worker     catch ( int i ) {}
177*c05d8e5dSAndroid Build Coastguard Worker 
178*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete ( one,       40, 0, throw_destruct );
179*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete2( two,       40, 0, throw_destruct, my_dealloc2 );
180*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete3( three,     40, 0, throw_destruct, my_dealloc3 );
181*c05d8e5dSAndroid Build Coastguard Worker 
182*c05d8e5dSAndroid Build Coastguard Worker //  Since there was no padding, the # of elements in the array are not stored
183*c05d8e5dSAndroid Build Coastguard Worker //  and the destructors are not called.
184*c05d8e5dSAndroid Build Coastguard Worker //  Since we threw after 15 calls to the constructor, we should see 5 calls to
185*c05d8e5dSAndroid Build Coastguard Worker //      the destructor from the partially constructed array.
186*c05d8e5dSAndroid Build Coastguard Worker     if ( gConstructorCounter - gDestructorCounter != 10 ) {
187*c05d8e5dSAndroid Build Coastguard Worker         std::cerr << "Mismatched Constructor/Destructor calls (1C)" << std::endl;
188*c05d8e5dSAndroid Build Coastguard Worker         std::cerr << gConstructorCounter << " constructors, but " <<
189*c05d8e5dSAndroid Build Coastguard Worker                 gDestructorCounter << " destructors" << std::endl;
190*c05d8e5dSAndroid Build Coastguard Worker         retVal = 1;
191*c05d8e5dSAndroid Build Coastguard Worker         }
192*c05d8e5dSAndroid Build Coastguard Worker 
193*c05d8e5dSAndroid Build Coastguard Worker     gConstructorCounter = gDestructorCounter = 0;
194*c05d8e5dSAndroid Build Coastguard Worker     gConstructorThrowTarget = 15;
195*c05d8e5dSAndroid Build Coastguard Worker     gDestructorThrowTarget  = -1;
196*c05d8e5dSAndroid Build Coastguard Worker     try {
197*c05d8e5dSAndroid Build Coastguard Worker         one = two = three = NULL;
198*c05d8e5dSAndroid Build Coastguard Worker         one     = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct );
199*c05d8e5dSAndroid Build Coastguard Worker         two     = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc2 );
200*c05d8e5dSAndroid Build Coastguard Worker         three   = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc3 );
201*c05d8e5dSAndroid Build Coastguard Worker         }
202*c05d8e5dSAndroid Build Coastguard Worker     catch ( int i ) {}
203*c05d8e5dSAndroid Build Coastguard Worker 
204*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete ( one,       40, 8, throw_destruct );
205*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete2( two,       40, 8, throw_destruct, my_dealloc2 );
206*c05d8e5dSAndroid Build Coastguard Worker     __cxxabiv1::__cxa_vec_delete3( three,     40, 8, throw_destruct, my_dealloc3 );
207*c05d8e5dSAndroid Build Coastguard Worker 
208*c05d8e5dSAndroid Build Coastguard Worker     if ( gConstructorCounter != gDestructorCounter ) {
209*c05d8e5dSAndroid Build Coastguard Worker         std::cerr << "Mismatched Constructor/Destructor calls (2C)" << std::endl;
210*c05d8e5dSAndroid Build Coastguard Worker         std::cerr << gConstructorCounter << " constructors, but " <<
211*c05d8e5dSAndroid Build Coastguard Worker                 gDestructorCounter << " destructors" << std::endl;
212*c05d8e5dSAndroid Build Coastguard Worker         retVal = 1;
213*c05d8e5dSAndroid Build Coastguard Worker         }
214*c05d8e5dSAndroid Build Coastguard Worker 
215*c05d8e5dSAndroid Build Coastguard Worker     return retVal;
216*c05d8e5dSAndroid Build Coastguard Worker     }
217*c05d8e5dSAndroid Build Coastguard Worker #endif
218*c05d8e5dSAndroid Build Coastguard Worker 
219*c05d8e5dSAndroid Build Coastguard Worker #ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
220*c05d8e5dSAndroid Build Coastguard Worker //  Make sure the constructors and destructors are matched
test_exception_in_destructor()221*c05d8e5dSAndroid Build Coastguard Worker int test_exception_in_destructor ( ) {
222*c05d8e5dSAndroid Build Coastguard Worker     int retVal = 0;
223*c05d8e5dSAndroid Build Coastguard Worker     void *one, *two, *three;
224*c05d8e5dSAndroid Build Coastguard Worker     one = two = three = NULL;
225*c05d8e5dSAndroid Build Coastguard Worker 
226*c05d8e5dSAndroid Build Coastguard Worker //  Throw from within a destructor
227*c05d8e5dSAndroid Build Coastguard Worker     gConstructorCounter = gDestructorCounter = 0;
228*c05d8e5dSAndroid Build Coastguard Worker     gConstructorThrowTarget = -1;
229*c05d8e5dSAndroid Build Coastguard Worker     gDestructorThrowTarget  = 15;
230*c05d8e5dSAndroid Build Coastguard Worker     try {
231*c05d8e5dSAndroid Build Coastguard Worker         one = two = NULL;
232*c05d8e5dSAndroid Build Coastguard Worker         one     = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct );
233*c05d8e5dSAndroid Build Coastguard Worker         two     = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc2 );
234*c05d8e5dSAndroid Build Coastguard Worker         }
235*c05d8e5dSAndroid Build Coastguard Worker     catch ( int i ) {}
236*c05d8e5dSAndroid Build Coastguard Worker 
237*c05d8e5dSAndroid Build Coastguard Worker     try {
238*c05d8e5dSAndroid Build Coastguard Worker         __cxxabiv1::__cxa_vec_delete ( one,       40, 8, throw_destruct );
239*c05d8e5dSAndroid Build Coastguard Worker         __cxxabiv1::__cxa_vec_delete2( two,       40, 8, throw_destruct, my_dealloc2 );
240*c05d8e5dSAndroid Build Coastguard Worker         assert(false);
241*c05d8e5dSAndroid Build Coastguard Worker         }
242*c05d8e5dSAndroid Build Coastguard Worker     catch ( int i ) {}
243*c05d8e5dSAndroid Build Coastguard Worker 
244*c05d8e5dSAndroid Build Coastguard Worker //  We should have thrown in the middle of cleaning up "two", which means that
245*c05d8e5dSAndroid Build Coastguard Worker //  there should be 20 calls to the destructor and the try block should exit
246*c05d8e5dSAndroid Build Coastguard Worker //  before the assertion.
247*c05d8e5dSAndroid Build Coastguard Worker     if ( gConstructorCounter != 20 || gDestructorCounter != 20 ) {
248*c05d8e5dSAndroid Build Coastguard Worker         std::cerr << "Unexpected Constructor/Destructor calls (1D)" << std::endl;
249*c05d8e5dSAndroid Build Coastguard Worker         std::cerr << "Expected (20, 20), but got (" << gConstructorCounter << ", " <<
250*c05d8e5dSAndroid Build Coastguard Worker                 gDestructorCounter << ")" << std::endl;
251*c05d8e5dSAndroid Build Coastguard Worker         retVal = 1;
252*c05d8e5dSAndroid Build Coastguard Worker         }
253*c05d8e5dSAndroid Build Coastguard Worker 
254*c05d8e5dSAndroid Build Coastguard Worker //  Try throwing from a destructor - should be fine.
255*c05d8e5dSAndroid Build Coastguard Worker     gConstructorCounter = gDestructorCounter = 0;
256*c05d8e5dSAndroid Build Coastguard Worker     gConstructorThrowTarget = -1;
257*c05d8e5dSAndroid Build Coastguard Worker     gDestructorThrowTarget  = 5;
258*c05d8e5dSAndroid Build Coastguard Worker     try { vec_on_stack v; }
259*c05d8e5dSAndroid Build Coastguard Worker     catch ( int i ) {}
260*c05d8e5dSAndroid Build Coastguard Worker 
261*c05d8e5dSAndroid Build Coastguard Worker     if ( gConstructorCounter != gDestructorCounter ) {
262*c05d8e5dSAndroid Build Coastguard Worker         std::cerr << "Mismatched Constructor/Destructor calls (2D)" << std::endl;
263*c05d8e5dSAndroid Build Coastguard Worker         std::cerr << gConstructorCounter << " constructors, but " <<
264*c05d8e5dSAndroid Build Coastguard Worker                 gDestructorCounter << " destructors" << std::endl;
265*c05d8e5dSAndroid Build Coastguard Worker         retVal = 1;
266*c05d8e5dSAndroid Build Coastguard Worker         }
267*c05d8e5dSAndroid Build Coastguard Worker 
268*c05d8e5dSAndroid Build Coastguard Worker     return retVal;
269*c05d8e5dSAndroid Build Coastguard Worker     }
270*c05d8e5dSAndroid Build Coastguard Worker #endif
271*c05d8e5dSAndroid Build Coastguard Worker 
main()272*c05d8e5dSAndroid Build Coastguard Worker int main () {
273*c05d8e5dSAndroid Build Coastguard Worker     int retVal = 0;
274*c05d8e5dSAndroid Build Coastguard Worker     retVal += test_empty ();
275*c05d8e5dSAndroid Build Coastguard Worker     retVal += test_counted ();
276*c05d8e5dSAndroid Build Coastguard Worker #ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
277*c05d8e5dSAndroid Build Coastguard Worker     retVal += test_exception_in_constructor ();
278*c05d8e5dSAndroid Build Coastguard Worker     retVal += test_exception_in_destructor ();
279*c05d8e5dSAndroid Build Coastguard Worker #endif
280*c05d8e5dSAndroid Build Coastguard Worker     return retVal;
281*c05d8e5dSAndroid Build Coastguard Worker     }
282