67 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: no-exceptions10 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#endif24 25// use dtors instead of try/catch26namespace test1 {27 struct B {28 ~B() {29 printf("should not be run\n");30 exit(10);31 }32};33 34struct A {35 ~A()36#if __has_feature(cxx_noexcept)37 noexcept(false)38#endif39 {40 B b;41 throw 0;42 }43};44} // test145 46void my_terminate() { exit(0); }47 48template <class T>49void destroy(void* v)50{51 T* t = static_cast<T*>(v);52 t->~T();53}54 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_dtor61 __cxxabiv1::__cxa_vec_dtor(a, 10, sizeof(test1::A), destroy<test1::A>);62 assert(false);63 }64 65 return 0;66}67