]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libc++/src/support/runtime/exception_pointer_msvc.ipp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / libc++ / src / support / runtime / exception_pointer_msvc.ipp
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include <stdio.h>
11 #include <stdlib.h>
12
13 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCreate(void*);
14 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrDestroy(void*);
15 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopy(void*, const void*);
16 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrAssign(void*, const void*);
17 _LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrCompare(const void*, const void*);
18 _LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrToBool(const void*);
19 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrSwap(void*, void*);
20 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCurrentException(void*);
21 [[noreturn]] _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrRethrow(const void*);
22 _LIBCPP_CRT_FUNC void __cdecl
23 __ExceptionPtrCopyException(void*, const void*, const void*);
24
25 namespace std {
26
27 exception_ptr::exception_ptr() _NOEXCEPT { __ExceptionPtrCreate(this); }
28 exception_ptr::exception_ptr(nullptr_t) _NOEXCEPT { __ExceptionPtrCreate(this); }
29
30 exception_ptr::exception_ptr(const exception_ptr& __other) _NOEXCEPT {
31   __ExceptionPtrCopy(this, &__other);
32 }
33 exception_ptr& exception_ptr::operator=(const exception_ptr& __other) _NOEXCEPT {
34   __ExceptionPtrAssign(this, &__other);
35   return *this;
36 }
37
38 exception_ptr& exception_ptr::operator=(nullptr_t) _NOEXCEPT {
39   exception_ptr dummy;
40   __ExceptionPtrAssign(this, &dummy);
41   return *this;
42 }
43
44 exception_ptr::~exception_ptr() _NOEXCEPT { __ExceptionPtrDestroy(this); }
45
46 exception_ptr::operator bool() const _NOEXCEPT {
47   return __ExceptionPtrToBool(this);
48 }
49
50 bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {
51   return __ExceptionPtrCompare(&__x, &__y);
52 }
53
54
55 void swap(exception_ptr& lhs, exception_ptr& rhs) _NOEXCEPT {
56   __ExceptionPtrSwap(&rhs, &lhs);
57 }
58
59 exception_ptr __copy_exception_ptr(void* __except, const void* __ptr) {
60   exception_ptr __ret = nullptr;
61   if (__ptr)
62     __ExceptionPtrCopyException(&__ret, __except, __ptr);
63   return __ret;
64 }
65
66 exception_ptr current_exception() _NOEXCEPT {
67   exception_ptr __ret;
68   __ExceptionPtrCurrentException(&__ret);
69   return __ret;
70 }
71
72 _LIBCPP_NORETURN
73 void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); }
74
75 nested_exception::nested_exception() _NOEXCEPT : __ptr_(current_exception()) {}
76
77 nested_exception::~nested_exception() _NOEXCEPT {}
78
79 _LIBCPP_NORETURN
80 void nested_exception::rethrow_nested() const {
81   if (__ptr_ == nullptr)
82     terminate();
83   rethrow_exception(__ptr_);
84 }
85
86 } // namespace std