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