1 // Exception Handling support header (exception_ptr class) for -*- C++ -*-
3 // Copyright (C) 2008, 2009 Free Software Foundation
5 // This file is part of GCC.
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)
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.
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.
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/>.
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.
31 #ifndef _EXCEPTION_PTR_H
32 #define _EXCEPTION_PTR_H
34 #pragma GCC visibility push(default)
36 #include <bits/c++config.h>
37 #include <exception_defines.h>
39 #if !defined(_GLIBCXX_ATOMIC_BUILTINS_4)
40 # error This platform does not support exception propagation.
48 * @addtogroup exceptions
52 // Hide the free operators from other types
53 namespace __exception_ptr
56 * @brief An opaque pointer to an arbitrary exception.
61 using __exception_ptr::exception_ptr;
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
67 exception_ptr current_exception() throw();
69 /// Throw the object pointed to by the %exception_ptr.
70 void rethrow_exception(exception_ptr) __attribute__ ((__noreturn__));
72 /// Obtain an %exception_ptr pointing to a copy of the supplied object.
73 template<typename _Ex>
75 copy_exception(_Ex __ex) throw();
77 namespace __exception_ptr
80 operator==(const exception_ptr&, const exception_ptr&) throw();
83 operator!=(const exception_ptr&, const exception_ptr&) throw();
87 void* _M_exception_object;
89 explicit exception_ptr(void* __e) throw();
91 void _M_addref() throw();
92 void _M_release() throw();
94 void *_M_get() const throw();
96 void _M_safe_bool_dummy();
98 friend exception_ptr std::current_exception() throw();
99 friend void std::rethrow_exception(exception_ptr);
102 exception_ptr() throw();
104 typedef void (exception_ptr::*__safe_bool)();
106 // For construction from nullptr or 0.
107 exception_ptr(__safe_bool) throw();
109 exception_ptr(const exception_ptr&) throw();
111 #ifdef __GXX_EXPERIMENTAL_CXX0X__
112 exception_ptr(exception_ptr&& __o) throw()
113 : _M_exception_object(__o._M_exception_object)
114 { __o._M_exception_object = 0; }
118 operator=(const exception_ptr&) throw();
120 #ifdef __GXX_EXPERIMENTAL_CXX0X__
122 operator=(exception_ptr&& __o) throw()
124 exception_ptr(static_cast<exception_ptr&&>(__o)).swap(*this);
129 ~exception_ptr() throw();
132 swap(exception_ptr&) throw();
134 #ifdef _GLIBCXX_EH_PTR_COMPAT
135 // Retained for compatibility with CXXABI_1.3.
136 bool operator!() const throw();
137 operator __safe_bool() const throw();
141 operator==(const exception_ptr&, const exception_ptr&) throw();
144 __cxa_exception_type() const throw();
147 } // namespace __exception_ptr
150 template<typename _Ex>
152 copy_exception(_Ex __ex) throw()
160 return current_exception ();
164 // @} group exceptions
169 #pragma GCC visibility pop