Home | History | Annotate | Download | only in propagation
      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 // UNSUPPORTED: 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 #ifndef _LIBCPP_ABI_MICROSOFT
     50             assert(A::constructed == 1);
     51 #else
     52             // On Windows the exception_ptr copies the exception
     53             assert(A::constructed == 2);
     54 #endif
     55             assert(p != nullptr);
     56             p = nullptr;
     57             assert(p == nullptr);
     58             assert(a.data_ == 3);
     59             assert(A::constructed == 1);
     60         }
     61         assert(A::constructed == 0);
     62     }
     63     assert(A::constructed == 0);
     64 }
     65