]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/libsupc++/exception_ptr.h
Add exception propagation support as per N2179.
[thirdparty/gcc.git] / libstdc++-v3 / libsupc++ / exception_ptr.h
1 // Exception Handling support header (exception_ptr class) for -*- C++ -*-
2
3 // Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 // 2004, 2005, 2006, 2007, 2008
5 // Free Software Foundation
6 //
7 // This file is part of GCC.
8 //
9 // GCC is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2, or (at your option)
12 // any later version.
13 //
14 // GCC is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with GCC; see the file COPYING. If not, write to
21 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 // Boston, MA 02110-1301, USA.
23
24 // As a special exception, you may use this file as part of a free software
25 // library without restriction. Specifically, if other files instantiate
26 // templates or use macros or inline functions from this file, or you compile
27 // this file and link it with other files to produce an executable, this
28 // file does not by itself cause the resulting executable to be covered by
29 // the GNU General Public License. This exception does not however
30 // invalidate any other reasons why the executable file might be covered by
31 // the GNU General Public License.
32
33 /** @file exception_ptr.h
34 * This is an internal header file, included by other headers and the
35 * implementation. You should not attempt to use it directly.
36 */
37
38 #ifndef __EXCEPTION_PTR_H__
39 #define __EXCEPTION_PTR_H__
40
41 #pragma GCC visibility push(default)
42
43 #include <bits/c++config.h>
44
45 extern "C++" {
46
47 namespace std
48 {
49 // Hide the free operators from other types
50 namespace __exception_ptr
51 {
52 /**
53 * @brief An opaque pointer to an arbitrary exception.
54 */
55 class exception_ptr;
56 }
57
58 using __exception_ptr::exception_ptr;
59
60 /** Obtain an %exception_ptr to the currently handled exception. If there
61 * is none, or the currently handled exception is foreign, return the null
62 * value.
63 */
64 exception_ptr current_exception() throw();
65
66 /// Throw the object pointed to by the %exception_ptr.
67 void rethrow_exception(exception_ptr) __attribute__ ((__noreturn__));
68
69 /// Obtain an %exception_ptr pointing to a copy of the supplied object.
70 template <class _Ex>
71 exception_ptr copy_exception(_Ex __ex) throw();
72
73
74 namespace __exception_ptr
75 {
76 bool operator==(const exception_ptr&,
77 const exception_ptr&) throw();
78 bool operator!=(const exception_ptr&,
79 const exception_ptr&) throw();
80
81 class exception_ptr
82 {
83 void* _M_exception_object;
84
85 explicit exception_ptr(void* __e) throw();
86
87 void _M_addref() throw();
88 void _M_release() throw();
89
90 void *_M_get() const throw();
91
92 void _M_safe_bool_dummy();
93
94 friend exception_ptr std::current_exception() throw();
95 friend void std::rethrow_exception(exception_ptr);
96
97 public:
98 exception_ptr() throw();
99
100 typedef void (exception_ptr::*__safe_bool)();
101
102 // For construction from nullptr or 0.
103 exception_ptr(__safe_bool) throw();
104
105 exception_ptr(const exception_ptr&) throw();
106
107 #ifdef __GXX_EXPERIMENTAL_CXX0X__
108 exception_ptr(exception_ptr&& __o) throw()
109 : _M_exception_object(__o._M_exception_object)
110 {
111 __o._M_exception_object = 0;
112 }
113 #endif
114
115 exception_ptr& operator=(const exception_ptr&) throw();
116
117 #ifdef __GXX_EXPERIMENTAL_CXX0X__
118 exception_ptr& operator=(exception_ptr&& __o) throw()
119 {
120 exception_ptr(__o).swap(*this);
121 return *this;
122 }
123 #endif
124
125 ~exception_ptr() throw();
126
127 void swap(exception_ptr&) throw();
128
129 #ifdef __GXX_EXPERIMENTAL_CXX0X__
130 void swap(exception_ptr &&__o) throw()
131 {
132 void *__tmp = _M_exception_object;
133 _M_exception_object = __o._M_exception_object;
134 __o._M_exception_object = __tmp;
135 }
136 #endif
137
138 bool operator!() const throw();
139 operator __safe_bool() const throw();
140
141 friend bool operator==(const exception_ptr&,
142 const exception_ptr&) throw();
143
144 const type_info *__cxa_exception_type() const throw();
145 };
146
147 } // namespace __exception_ptr
148
149
150 template <class _Ex>
151 exception_ptr copy_exception(_Ex __ex) throw()
152 {
153 try
154 {
155 throw __ex;
156 }
157 catch(...)
158 {
159 return current_exception ();
160 }
161 }
162
163 } // namespace std
164
165 } // extern "C++"
166
167 #pragma GCC visibility pop
168
169 #endif