1*eb8650a7SLouis Dionne //===----------------------------------------------------------------------===// 2e434b34fSJonathan Roelofs // 357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e434b34fSJonathan Roelofs // 7e434b34fSJonathan Roelofs //===----------------------------------------------------------------------===// 8e434b34fSJonathan Roelofs 98c61114cSLouis Dionne // UNSUPPORTED: no-exceptions 1057e446daSAsiri Rathnayake 11e434b34fSJonathan Roelofs #include "cxxabi.h" 12e434b34fSJonathan Roelofs 13e434b34fSJonathan Roelofs #include <stdio.h> 14e434b34fSJonathan Roelofs #include <stdlib.h> 15e434b34fSJonathan Roelofs #include <assert.h> 16e434b34fSJonathan Roelofs #include <exception> 17e434b34fSJonathan Roelofs 18e434b34fSJonathan Roelofs #include <memory> 19e434b34fSJonathan Roelofs 208d313927SLouis Dionne // Disable warning about throw always calling terminate. 218d313927SLouis Dionne #if defined(__GNUC__) && !defined(__clang__) 228d313927SLouis Dionne # pragma GCC diagnostic ignored "-Wterminate" 238d313927SLouis Dionne #endif 248d313927SLouis Dionne 25e434b34fSJonathan Roelofs // use dtors instead of try/catch 26e434b34fSJonathan Roelofs namespace test1 { 27e434b34fSJonathan Roelofs struct B { ~Btest1::B28e434b34fSJonathan Roelofs ~B() { 29e434b34fSJonathan Roelofs printf("should not be run\n"); 30e434b34fSJonathan Roelofs exit(10); 31e434b34fSJonathan Roelofs } 32e434b34fSJonathan Roelofs }; 33e434b34fSJonathan Roelofs 34e434b34fSJonathan Roelofs struct A { ~Atest1::A35e434b34fSJonathan Roelofs ~A() 36e434b34fSJonathan Roelofs #if __has_feature(cxx_noexcept) 37e434b34fSJonathan Roelofs noexcept(false) 38e434b34fSJonathan Roelofs #endif 39e434b34fSJonathan Roelofs { 40e434b34fSJonathan Roelofs B b; 41e434b34fSJonathan Roelofs throw 0; 42e434b34fSJonathan Roelofs } 43e434b34fSJonathan Roelofs }; 44e434b34fSJonathan Roelofs } // test1 45e434b34fSJonathan Roelofs my_terminate()46e434b34fSJonathan Roelofsvoid my_terminate() { exit(0); } 47e434b34fSJonathan Roelofs 48e434b34fSJonathan Roelofs template <class T> destroy(void * v)49e434b34fSJonathan Roelofsvoid destroy(void* v) 50e434b34fSJonathan Roelofs { 51e434b34fSJonathan Roelofs T* t = static_cast<T*>(v); 52e434b34fSJonathan Roelofs t->~T(); 53e434b34fSJonathan Roelofs } 54e434b34fSJonathan Roelofs main(int,char **)55504bc07dSLouis Dionneint main(int, char**) 56e434b34fSJonathan Roelofs { 57e434b34fSJonathan Roelofs std::set_terminate(my_terminate); 58e434b34fSJonathan Roelofs { 59e434b34fSJonathan Roelofs typedef test1::A Array[10]; 60e434b34fSJonathan Roelofs Array a[10]; // calls _cxa_vec_dtor 61e434b34fSJonathan Roelofs __cxxabiv1::__cxa_vec_dtor(a, 10, sizeof(test1::A), destroy<test1::A>); 62e434b34fSJonathan Roelofs assert(false); 63e434b34fSJonathan Roelofs } 64504bc07dSLouis Dionne 65504bc07dSLouis Dionne return 0; 66e434b34fSJonathan Roelofs } 67