make_exception_ptr.pass.cpp (1383B)
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 // template<class E> exception_ptr make_exception_ptr(E e); 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 = std::make_exception_ptr(A(5)); 34 try 35 { 36 std::rethrow_exception(p); 37 assert(false); 38 } 39 catch (const A& a) 40 { 41 #ifndef _LIBCPP_ABI_MICROSOFT 42 assert(A::constructed == 1); 43 #else 44 // On Windows exception_ptr copies the exception 45 assert(A::constructed == 2); 46 #endif 47 assert(p != nullptr); 48 p = nullptr; 49 assert(p == nullptr); 50 assert(a.data_ == 5); 51 assert(A::constructed == 1); 52 } 53 assert(A::constructed == 0); 54 } 55 assert(A::constructed == 0); 56 }