1 | //===----------------------------------------------------------------------===// |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: no-exceptions |
10 | |
11 | #include "cxxabi.h" |
12 | |
13 | #include <stdio.h> |
14 | #include <stdlib.h> |
15 | #include <assert.h> |
16 | #include <exception> |
17 | |
18 | #include <memory> |
19 | |
20 | // Disable warning about throw always calling terminate. |
21 | #if defined(__GNUC__) && !defined(__clang__) |
22 | # pragma GCC diagnostic ignored "-Wterminate" |
23 | #endif |
24 | |
25 | // use dtors instead of try/catch |
26 | namespace test1 { |
27 | struct B { |
28 | ~B() { |
29 | printf(format: "should not be run\n" ); |
30 | exit(status: 10); |
31 | } |
32 | }; |
33 | |
34 | struct A { |
35 | ~A() |
36 | #if __has_feature(cxx_noexcept) |
37 | noexcept(false) |
38 | #endif |
39 | { |
40 | B b; |
41 | throw 0; |
42 | } |
43 | }; |
44 | } // test1 |
45 | |
46 | void my_terminate() { exit(status: 0); } |
47 | |
48 | template <class T> |
49 | void destroy(void* v) |
50 | { |
51 | T* t = static_cast<T*>(v); |
52 | t->~T(); |
53 | } |
54 | |
55 | int main(int, char**) |
56 | { |
57 | std::set_terminate(my_terminate); |
58 | { |
59 | typedef test1::A Array[10]; |
60 | Array a[10]; // calls _cxa_vec_dtor |
61 | __cxxabiv1::__cxa_vec_dtor(array_address: a, element_count: 10, element_size: sizeof(test1::A), destructor: destroy<test1::A>); |
62 | assert(false); |
63 | } |
64 | |
65 | return 0; |
66 | } |
67 | |