libcxxabi

libcxxabi mirror with random patches
git clone https://git.neptards.moe/neptards/libcxxabi.git
Log | Files | Refs

test_vector3.pass.cpp (1141B)


      1 //===------------------------- test_vector3.cpp ---------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // UNSUPPORTED: libcxxabi-no-exceptions
     11 
     12 #include "cxxabi.h"
     13 
     14 #include <stdio.h>
     15 #include <stdlib.h>
     16 #include <assert.h>
     17 #include <exception>
     18 
     19 #include <memory>
     20 
     21 // use dtors instead of try/catch
     22 namespace test1 {
     23     struct B {
     24          ~B() {
     25             printf("should not be run\n");
     26             exit(10);
     27             }
     28 };
     29 
     30 struct A {
     31  ~A()
     32 #if __has_feature(cxx_noexcept)
     33     noexcept(false)
     34 #endif
     35  {
     36    B b;
     37    throw 0;
     38  }
     39 };
     40 }  // test1
     41 
     42 void my_terminate() { exit(0); }
     43 
     44 template <class T>
     45 void destroy(void* v)
     46 {
     47   T* t = static_cast<T*>(v);
     48   t->~T();
     49 }
     50 
     51 int main()
     52 {
     53   std::set_terminate(my_terminate);
     54   {
     55   typedef test1::A Array[10];
     56   Array a[10]; // calls _cxa_vec_dtor
     57   __cxxabiv1::__cxa_vec_dtor(a, 10, sizeof(test1::A), destroy<test1::A>);
     58   assert(false);
     59   }
     60 }