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