1 //===------------------------- test_vector3.cpp ---------------------------===// 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 { ~Btest1::B28 ~B() { 29 printf("should not be run\n"); 30 exit(10); 31 } 32 }; 33 34 struct A { ~Atest1::A35 ~A() 36 #if __has_feature(cxx_noexcept) 37 noexcept(false) 38 #endif 39 { 40 B b; 41 throw 0; 42 } 43 }; 44 } // test1 45 my_terminate()46void my_terminate() { exit(0); } 47 48 template <class T> destroy(void * v)49void destroy(void* v) 50 { 51 T* t = static_cast<T*>(v); 52 t->~T(); 53 } 54 main(int,char **)55int 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(a, 10, sizeof(test1::A), destroy<test1::A>); 62 assert(false); 63 } 64 65 return 0; 66 } 67