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