Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __exception / exception_ptr.h
blob970d8196724b7cb952a0385b7434c5f8dc92b262
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___EXCEPTION_EXCEPTION_PTR_H
10 #define _LIBCPP___EXCEPTION_EXCEPTION_PTR_H
12 #include <__config>
13 #include <__exception/operations.h>
14 #include <__memory/addressof.h>
15 #include <cstddef>
16 #include <cstdlib>
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 # pragma GCC system_header
20 #endif
22 namespace std { // purposefully not using versioning namespace
24 #ifndef _LIBCPP_ABI_MICROSOFT
26 class _LIBCPP_EXPORTED_FROM_ABI exception_ptr {
27 void* __ptr_;
29 public:
30 _LIBCPP_HIDE_FROM_ABI exception_ptr() _NOEXCEPT : __ptr_() {}
31 _LIBCPP_HIDE_FROM_ABI exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {}
33 exception_ptr(const exception_ptr&) _NOEXCEPT;
34 exception_ptr& operator=(const exception_ptr&) _NOEXCEPT;
35 ~exception_ptr() _NOEXCEPT;
37 _LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return __ptr_ != nullptr; }
39 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {
40 return __x.__ptr_ == __y.__ptr_;
43 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {
44 return !(__x == __y);
47 friend _LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT;
48 friend _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr);
51 template <class _Ep>
52 _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
53 # ifndef _LIBCPP_HAS_NO_EXCEPTIONS
54 try {
55 throw __e;
56 } catch (...) {
57 return current_exception();
59 # else
60 ((void)__e);
61 std::abort();
62 # endif
65 #else // _LIBCPP_ABI_MICROSOFT
67 class _LIBCPP_EXPORTED_FROM_ABI exception_ptr {
68 _LIBCPP_DIAGNOSTIC_PUSH
69 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field")
70 void* __ptr1_;
71 void* __ptr2_;
72 _LIBCPP_DIAGNOSTIC_POP
74 public:
75 exception_ptr() _NOEXCEPT;
76 exception_ptr(nullptr_t) _NOEXCEPT;
77 exception_ptr(const exception_ptr& __other) _NOEXCEPT;
78 exception_ptr& operator=(const exception_ptr& __other) _NOEXCEPT;
79 exception_ptr& operator=(nullptr_t) _NOEXCEPT;
80 ~exception_ptr() _NOEXCEPT;
81 explicit operator bool() const _NOEXCEPT;
84 _LIBCPP_EXPORTED_FROM_ABI bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT;
86 inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {
87 return !(__x == __y);
90 _LIBCPP_EXPORTED_FROM_ABI void swap(exception_ptr&, exception_ptr&) _NOEXCEPT;
92 _LIBCPP_EXPORTED_FROM_ABI exception_ptr __copy_exception_ptr(void* __except, const void* __ptr);
93 _LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT;
94 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr);
96 // This is a built-in template function which automagically extracts the required
97 // information.
98 template <class _E>
99 void* __GetExceptionInfo(_E);
101 template <class _Ep>
102 _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
103 return __copy_exception_ptr(std::addressof(__e), __GetExceptionInfo(__e));
106 #endif // _LIBCPP_ABI_MICROSOFT
107 } // namespace std
109 #endif // _LIBCPP___EXCEPTION_EXCEPTION_PTR_H