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_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCreate(void*); 15_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrDestroy(void*); 16_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopy(void*, const void*); 17_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrAssign(void*, const void*); 18_LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrCompare(const void*, const void*); 19_LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrToBool(const void*); 20_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrSwap(void*, void*); 21_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCurrentException(void*); 22[[noreturn]] _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrRethrow(const void*); 23_LIBCPP_CRT_FUNC void __cdecl 24__ExceptionPtrCopyException(void*, const void*, const void*); 25 26namespace std { 27 28exception_ptr::exception_ptr() _NOEXCEPT { __ExceptionPtrCreate(this); } 29exception_ptr::exception_ptr(nullptr_t) _NOEXCEPT { __ExceptionPtrCreate(this); } 30 31exception_ptr::exception_ptr(const exception_ptr& __other) _NOEXCEPT { 32 __ExceptionPtrCopy(this, &__other); 33} 34exception_ptr& exception_ptr::operator=(const exception_ptr& __other) _NOEXCEPT { 35 __ExceptionPtrAssign(this, &__other); 36 return *this; 37} 38 39exception_ptr& exception_ptr::operator=(nullptr_t) _NOEXCEPT { 40 exception_ptr dummy; 41 __ExceptionPtrAssign(this, &dummy); 42 return *this; 43} 44 45exception_ptr::~exception_ptr() _NOEXCEPT { __ExceptionPtrDestroy(this); } 46 47exception_ptr::operator bool() const _NOEXCEPT { 48 return __ExceptionPtrToBool(this); 49} 50 51bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT { 52 return __ExceptionPtrCompare(&__x, &__y); 53} 54 55 56void swap(exception_ptr& lhs, exception_ptr& rhs) _NOEXCEPT { 57 __ExceptionPtrSwap(&rhs, &lhs); 58} 59 60exception_ptr __copy_exception_ptr(void* __except, const void* __ptr) { 61 exception_ptr __ret = nullptr; 62 if (__ptr) 63 __ExceptionPtrCopyException(&__ret, __except, __ptr); 64 return __ret; 65} 66 67exception_ptr current_exception() _NOEXCEPT { 68 exception_ptr __ret; 69 __ExceptionPtrCurrentException(&__ret); 70 return __ret; 71} 72 73_LIBCPP_NORETURN 74void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); } 75 76nested_exception::nested_exception() _NOEXCEPT : __ptr_(current_exception()) {} 77 78nested_exception::~nested_exception() _NOEXCEPT {} 79 80_LIBCPP_NORETURN 81void nested_exception::rethrow_nested() const { 82 if (__ptr_ == nullptr) 83 terminate(); 84 rethrow_exception(__ptr_); 85} 86 87} // namespace std 88