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