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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: libcpp-no-exceptions 10 // <exception> 11 12 // void rethrow_exception [[noreturn]] (exception_ptr p); 13 14 #include <exception> 15 #include <cassert> 16 17 struct A 18 { 19 static int constructed; 20 int data_; 21 22 A(int data = 0) : data_(data) {++constructed;} 23 ~A() {--constructed;} 24 A(const A& a) : data_(a.data_) {++constructed;} 25 }; 26 27 int A::constructed = 0; 28 29 int main() 30 { 31 { 32 std::exception_ptr p; 33 try 34 { 35 throw A(3); 36 } 37 catch (...) 38 { 39 p = std::current_exception(); 40 } 41 try 42 { 43 std::rethrow_exception(p); 44 assert(false); 45 } 46 catch (const A& a) 47 { 48 #ifndef _LIBCPP_ABI_MICROSOFT 49 assert(A::constructed == 1); 50 #else 51 // On Windows the exception_ptr copies the exception 52 assert(A::constructed == 2); 53 #endif 54 assert(p != nullptr); 55 p = nullptr; 56 assert(p == nullptr); 57 assert(a.data_ == 3); 58 assert(A::constructed == 1); 59 } 60 assert(A::constructed == 0); 61 } 62 assert(A::constructed == 0); 63 } 64