]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/libsupc++/exception_ptr.h
re PR libstdc++/40296 ([C++0x] std::exception_ptr comparisons)
[thirdparty/gcc.git] / libstdc++-v3 / libsupc++ / exception_ptr.h
1 // Exception Handling support header (exception_ptr class) for -*- C++ -*-
2
3 // Copyright (C) 2008, 2009 Free Software Foundation
4 //
5 // This file is part of GCC.
6 //
7 // GCC is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11 //
12 // GCC is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
20
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
25
26 /** @file exception_ptr.h
27 * This is an internal header file, included by other headers and the
28 * implementation. You should not attempt to use it directly.
29 */
30
31 #ifndef _EXCEPTION_PTR_H
32 #define _EXCEPTION_PTR_H
33
34 #pragma GCC visibility push(default)
35
36 #include <bits/c++config.h>
37 #include <exception_defines.h>
38
39 #if !defined(_GLIBCXX_ATOMIC_BUILTINS_4)
40 # error This platform does not support exception propagation.
41 #endif
42
43 extern "C++" {
44
45 namespace std
46 {
47 /**
48 * @addtogroup exceptions
49 * @{
50 */
51
52 // Hide the free operators from other types
53 namespace __exception_ptr
54 {
55 /**
56 * @brief An opaque pointer to an arbitrary exception.
57 */
58 class exception_ptr;
59 }
60
61 using __exception_ptr::exception_ptr;
62
63 /** Obtain an %exception_ptr to the currently handled exception. If there
64 * is none, or the currently handled exception is foreign, return the null
65 * value.
66 */
67 exception_ptr current_exception() throw();
68
69 /// Throw the object pointed to by the %exception_ptr.
70 void rethrow_exception(exception_ptr) __attribute__ ((__noreturn__));
71
72 /// Obtain an %exception_ptr pointing to a copy of the supplied object.
73 template<typename _Ex>
74 exception_ptr
75 copy_exception(_Ex __ex) throw();
76
77 namespace __exception_ptr
78 {
79 bool
80 operator==(const exception_ptr&, const exception_ptr&)
81 throw() __attribute__ ((__pure__));
82
83 bool
84 operator!=(const exception_ptr&, const exception_ptr&)
85 throw() __attribute__ ((__pure__));
86
87 class exception_ptr
88 {
89 void* _M_exception_object;
90
91 explicit exception_ptr(void* __e) throw();
92
93 void _M_addref() throw();
94 void _M_release() throw();
95
96 void *_M_get() const throw() __attribute__ ((__pure__));
97
98 void _M_safe_bool_dummy() throw() __attribute__ ((__const__));
99
100 friend exception_ptr std::current_exception() throw();
101 friend void std::rethrow_exception(exception_ptr);
102
103 public:
104 exception_ptr() throw();
105
106 typedef void (exception_ptr::*__safe_bool)();
107
108 // For construction from nullptr or 0.
109 exception_ptr(__safe_bool) throw();
110
111 exception_ptr(const exception_ptr&) throw();
112
113 #ifdef __GXX_EXPERIMENTAL_CXX0X__
114 exception_ptr(exception_ptr&& __o) throw()
115 : _M_exception_object(__o._M_exception_object)
116 { __o._M_exception_object = 0; }
117 #endif
118
119 exception_ptr&
120 operator=(const exception_ptr&) throw();
121
122 #ifdef __GXX_EXPERIMENTAL_CXX0X__
123 exception_ptr&
124 operator=(exception_ptr&& __o) throw()
125 {
126 exception_ptr(__o).swap(*this);
127 return *this;
128 }
129 #endif
130
131 ~exception_ptr() throw();
132
133 void
134 swap(exception_ptr&) throw();
135
136 #ifdef __GXX_EXPERIMENTAL_CXX0X__
137 void
138 swap(exception_ptr &&__o) throw()
139 {
140 void *__tmp = _M_exception_object;
141 _M_exception_object = __o._M_exception_object;
142 __o._M_exception_object = __tmp;
143 }
144 #endif
145
146 #ifdef _GLIBCXX_EH_PTR_COMPAT
147 // Retained for compatibility with CXXABI_1.3.
148 bool operator!() const throw() __attribute__ ((__pure__));
149 operator __safe_bool() const throw();
150 #endif
151
152 friend bool
153 operator==(const exception_ptr&, const exception_ptr&)
154 throw() __attribute__ ((__pure__));
155
156 const type_info*
157 __cxa_exception_type() const throw() __attribute__ ((__pure__));
158 };
159
160 } // namespace __exception_ptr
161
162
163 template<typename _Ex>
164 exception_ptr
165 copy_exception(_Ex __ex) throw()
166 {
167 __try
168 {
169 throw __ex;
170 }
171 __catch(...)
172 {
173 return current_exception ();
174 }
175 }
176
177 // @} group exceptions
178 } // namespace std
179
180 } // extern "C++"
181
182 #pragma GCC visibility pop
183
184 #endif