1 //===----------------------------------------------------------------------===// 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 // exception_ptr has not been implemented on Windows 11 // XFAIL: LIBCXX-WINDOWS-FIXME 12 13 // UNSUPPORTED: libcpp-no-exceptions 14 // <exception> 15 16 // class nested_exception; 17 18 // void rethrow_nested [[noreturn]] () const; 19 20 #include <exception> 21 #include <cstdlib> 22 #include <cassert> 23 24 class A 25 { 26 int data_; 27 public: 28 explicit A(int data) : data_(data) {} 29 30 friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;} 31 }; 32 33 void go_quietly() 34 { 35 std::exit(0); 36 } 37 38 int main() 39 { 40 { 41 try 42 { 43 throw A(2); 44 assert(false); 45 } 46 catch (const A&) 47 { 48 const std::nested_exception e; 49 assert(e.nested_ptr() != nullptr); 50 try 51 { 52 e.rethrow_nested(); 53 assert(false); 54 } 55 catch (const A& a) 56 { 57 assert(a == A(2)); 58 } 59 } 60 } 61 { 62 try 63 { 64 std::set_terminate(go_quietly); 65 const std::nested_exception e; 66 e.rethrow_nested(); 67 assert(false); 68 } 69 catch (...) 70 { 71 assert(false); 72 } 73 } 74 } 75