1 //===--------------------------- test_vector2.cpp -------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: libcxxabi-no-exceptions
16 void my_terminate () { exit ( 0 ); }
19 void *my_alloc2 ( size_t sz
) {
20 void *p
= std::malloc ( sz
);
21 // std::printf ( "Allocated %ld bytes at %lx\n", sz, (unsigned long) p );
25 void my_dealloc2 ( void *p
) {
26 // std::printf ( "Freeing %lx\n", (unsigned long) p );
30 void my_dealloc3 ( void *p
, size_t ) {
31 // std::printf ( "Freeing %lx (size %ld)\n", (unsigned long) p, sz );
35 void my_construct ( void *) {
36 // std::printf ( "Constructing %lx\n", (unsigned long) p );
39 void my_destruct ( void *) {
40 // std::printf ( "Destructing %lx\n", (unsigned long) p );
44 void count_construct ( void * ) { ++gCounter
; }
45 void count_destruct ( void * ) { --gCounter
; }
48 int gConstructorCounter
;
49 int gConstructorThrowTarget
;
50 int gDestructorCounter
;
51 int gDestructorThrowTarget
;
52 void throw_construct ( void * ) { if ( gConstructorCounter
== gConstructorThrowTarget
) throw 1; ++gConstructorCounter
; }
53 void throw_destruct ( void * ) { if ( ++gDestructorCounter
== gDestructorThrowTarget
) throw 2; }
57 vec_on_stack () : storage ( __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct
, throw_destruct
)) {}
58 ~vec_on_stack () { __cxxabiv1::__cxa_vec_delete ( storage
, 40, 8, throw_destruct
); }
62 // Make sure the constructors and destructors are matched
63 void test_exception_in_destructor ( ) {
65 // Try throwing from a destructor while unwinding the stack -- should abort
66 gConstructorCounter
= gDestructorCounter
= 0;
67 gConstructorThrowTarget
= -1;
68 gDestructorThrowTarget
= 5;
75 std::cerr
<< "should never get here" << std::endl
;
81 std::set_terminate ( my_terminate
);
82 test_exception_in_destructor ();
83 return 1; // we failed if we get here