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 // void rethrow_exception [[noreturn]] (exception_ptr p); 17 18 #include <exception> 19 #include <cassert> 20 21 struct A 22 { 23 static int constructed; 24 int data_; 25 26 A(int data = 0) : data_(data) {++constructed;} 27 ~A() {--constructed;} 28 A(const A& a) : data_(a.data_) {++constructed;} 29 }; 30 31 int A::constructed = 0; 32 33 int main() 34 { 35 { 36 std::exception_ptr p; 37 try 38 { 39 throw A(3); 40 } 41 catch (...) 42 { 43 p = std::current_exception(); 44 } 45 try 46 { 47 std::rethrow_exception(p); 48 assert(false); 49 } 50 catch (const A& a) 51 { 52 assert(A::constructed == 1); 53 assert(p != nullptr); 54 p = nullptr; 55 assert(p == nullptr); 56 assert(a.data_ == 3); 57 assert(A::constructed == 1); 58 } 59 assert(A::constructed == 0); 60 } 61 } 62