1// -*- C++ -*- 2//===----------------------------------------------------------------------===// 3// 4// The LLVM Compiler Infrastructure 5// 6// This file is dual licensed under the MIT and the University of Illinois Open 7// Source Licenses. See LICENSE.TXT for details. 8// 9//===----------------------------------------------------------------------===// 10 11#include <stdio.h> 12#include <stdlib.h> 13 14#if !defined(_CRTIMP2_PURE) 15#define _CRTIMP2_PURE __declspec(dllimport) 16#endif 17 18#if !defined(__CLRCALL_PURE_OR_CDECL) 19#define __CLRCALL_PURE_OR_CDECL __cdecl 20#endif 21 22_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCreate(void*); 23_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrDestroy(void*); 24_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCopy(void*, 25 const void*); 26_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL 27__ExceptionPtrAssign(void*, const void*); 28_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL 29__ExceptionPtrCompare(const void*, const void*); 30_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL 31__ExceptionPtrToBool(const void*); 32_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrSwap(void*, void*); 33_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL 34__ExceptionPtrCurrentException(void*); 35[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL 36__ExceptionPtrRethrow(const void*); 37_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL 38__ExceptionPtrCopyException(void*, const void*, const void*); 39 40namespace std { 41 42exception_ptr::exception_ptr() _NOEXCEPT { __ExceptionPtrCreate(this); } 43exception_ptr::exception_ptr(nullptr_t) _NOEXCEPT { __ExceptionPtrCreate(this); } 44 45exception_ptr::exception_ptr(const exception_ptr& __other) _NOEXCEPT { 46 __ExceptionPtrCopy(this, &__other); 47} 48exception_ptr& exception_ptr::operator=(const exception_ptr& __other) _NOEXCEPT { 49 __ExceptionPtrAssign(this, &__other); 50 return *this; 51} 52 53exception_ptr& exception_ptr::operator=(nullptr_t) _NOEXCEPT { 54 exception_ptr dummy; 55 __ExceptionPtrAssign(this, &dummy); 56 return *this; 57} 58 59exception_ptr::~exception_ptr() _NOEXCEPT { __ExceptionPtrDestroy(this); } 60 61exception_ptr::operator bool() const _NOEXCEPT { 62 return __ExceptionPtrToBool(this); 63} 64 65bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT { 66 return __ExceptionPtrCompare(&__x, &__y); 67} 68 69 70void swap(exception_ptr& lhs, exception_ptr& rhs) _NOEXCEPT { 71 __ExceptionPtrSwap(&rhs, &lhs); 72} 73 74exception_ptr __copy_exception_ptr(void* __except, const void* __ptr) { 75 exception_ptr __ret = nullptr; 76 if (__ptr) 77 __ExceptionPtrCopyException(&__ret, __except, __ptr); 78 return __ret; 79} 80 81exception_ptr current_exception() _NOEXCEPT { 82 exception_ptr __ret; 83 __ExceptionPtrCurrentException(&__ret); 84 return __ret; 85} 86 87_LIBCPP_NORETURN 88void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); } 89 90nested_exception::nested_exception() _NOEXCEPT : __ptr_(current_exception()) {} 91 92nested_exception::~nested_exception() _NOEXCEPT {} 93 94_LIBCPP_NORETURN 95void nested_exception::rethrow_nested() const { 96 if (__ptr_ == nullptr) 97 terminate(); 98 rethrow_exception(__ptr_); 99} 100 101} // namespace std 102