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