libstdc++
|
00001 // Exception Handling support header (exception_ptr class) for -*- C++ -*- 00002 00003 // Copyright (C) 2008-2016 Free Software Foundation, Inc. 00004 // 00005 // This file is part of GCC. 00006 // 00007 // GCC is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 3, or (at your option) 00010 // any later version. 00011 // 00012 // GCC is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // Under Section 7 of GPL version 3, you are granted additional 00018 // permissions described in the GCC Runtime Library Exception, version 00019 // 3.1, as published by the Free Software Foundation. 00020 00021 // You should have received a copy of the GNU General Public License and 00022 // a copy of the GCC Runtime Library Exception along with this program; 00023 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00024 // <http://www.gnu.org/licenses/>. 00025 00026 /** @file bits/exception_ptr.h 00027 * This is an internal header file, included by other library headers. 00028 * Do not attempt to use it directly. @headername{exception} 00029 */ 00030 00031 #ifndef _EXCEPTION_PTR_H 00032 #define _EXCEPTION_PTR_H 00033 00034 #pragma GCC visibility push(default) 00035 00036 #include <bits/c++config.h> 00037 #include <bits/exception_defines.h> 00038 00039 #if ATOMIC_INT_LOCK_FREE < 2 00040 # error This platform does not support exception propagation. 00041 #endif 00042 00043 extern "C++" { 00044 00045 namespace std 00046 { 00047 class type_info; 00048 00049 /** 00050 * @addtogroup exceptions 00051 * @{ 00052 */ 00053 namespace __exception_ptr 00054 { 00055 class exception_ptr; 00056 } 00057 00058 using __exception_ptr::exception_ptr; 00059 00060 /** Obtain an exception_ptr to the currently handled exception. If there 00061 * is none, or the currently handled exception is foreign, return the null 00062 * value. 00063 */ 00064 exception_ptr current_exception() _GLIBCXX_USE_NOEXCEPT; 00065 00066 /// Throw the object pointed to by the exception_ptr. 00067 void rethrow_exception(exception_ptr) __attribute__ ((__noreturn__)); 00068 00069 namespace __exception_ptr 00070 { 00071 using std::rethrow_exception; 00072 00073 /** 00074 * @brief An opaque pointer to an arbitrary exception. 00075 * @ingroup exceptions 00076 */ 00077 class exception_ptr 00078 { 00079 void* _M_exception_object; 00080 00081 explicit exception_ptr(void* __e) _GLIBCXX_USE_NOEXCEPT; 00082 00083 void _M_addref() _GLIBCXX_USE_NOEXCEPT; 00084 void _M_release() _GLIBCXX_USE_NOEXCEPT; 00085 00086 void *_M_get() const _GLIBCXX_NOEXCEPT __attribute__ ((__pure__)); 00087 00088 friend exception_ptr std::current_exception() _GLIBCXX_USE_NOEXCEPT; 00089 friend void std::rethrow_exception(exception_ptr); 00090 00091 public: 00092 exception_ptr() _GLIBCXX_USE_NOEXCEPT; 00093 00094 exception_ptr(const exception_ptr&) _GLIBCXX_USE_NOEXCEPT; 00095 00096 #if __cplusplus >= 201103L 00097 exception_ptr(nullptr_t) noexcept 00098 : _M_exception_object(0) 00099 { } 00100 00101 exception_ptr(exception_ptr&& __o) noexcept 00102 : _M_exception_object(__o._M_exception_object) 00103 { __o._M_exception_object = 0; } 00104 #endif 00105 00106 #if (__cplusplus < 201103L) || defined (_GLIBCXX_EH_PTR_COMPAT) 00107 typedef void (exception_ptr::*__safe_bool)(); 00108 00109 // For construction from nullptr or 0. 00110 exception_ptr(__safe_bool) _GLIBCXX_USE_NOEXCEPT; 00111 #endif 00112 00113 exception_ptr& 00114 operator=(const exception_ptr&) _GLIBCXX_USE_NOEXCEPT; 00115 00116 #if __cplusplus >= 201103L 00117 exception_ptr& 00118 operator=(exception_ptr&& __o) noexcept 00119 { 00120 exception_ptr(static_cast<exception_ptr&&>(__o)).swap(*this); 00121 return *this; 00122 } 00123 #endif 00124 00125 ~exception_ptr() _GLIBCXX_USE_NOEXCEPT; 00126 00127 void 00128 swap(exception_ptr&) _GLIBCXX_USE_NOEXCEPT; 00129 00130 #ifdef _GLIBCXX_EH_PTR_COMPAT 00131 // Retained for compatibility with CXXABI_1.3. 00132 void _M_safe_bool_dummy() _GLIBCXX_USE_NOEXCEPT 00133 __attribute__ ((__const__)); 00134 bool operator!() const _GLIBCXX_USE_NOEXCEPT 00135 __attribute__ ((__pure__)); 00136 operator __safe_bool() const _GLIBCXX_USE_NOEXCEPT; 00137 #endif 00138 00139 #if __cplusplus >= 201103L 00140 explicit operator bool() const 00141 { return _M_exception_object; } 00142 #endif 00143 00144 friend bool 00145 operator==(const exception_ptr&, const exception_ptr&) 00146 _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__)); 00147 00148 const class std::type_info* 00149 __cxa_exception_type() const _GLIBCXX_USE_NOEXCEPT 00150 __attribute__ ((__pure__)); 00151 }; 00152 00153 bool 00154 operator==(const exception_ptr&, const exception_ptr&) 00155 _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__)); 00156 00157 bool 00158 operator!=(const exception_ptr&, const exception_ptr&) 00159 _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__)); 00160 00161 inline void 00162 swap(exception_ptr& __lhs, exception_ptr& __rhs) 00163 { __lhs.swap(__rhs); } 00164 00165 } // namespace __exception_ptr 00166 00167 00168 /// Obtain an exception_ptr pointing to a copy of the supplied object. 00169 template<typename _Ex> 00170 exception_ptr 00171 make_exception_ptr(_Ex __ex) _GLIBCXX_USE_NOEXCEPT 00172 { 00173 #if __cpp_exceptions 00174 try 00175 { 00176 throw __ex; 00177 } 00178 catch(...) 00179 { 00180 return current_exception(); 00181 } 00182 #else 00183 return exception_ptr(); 00184 #endif 00185 } 00186 00187 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00188 // 1130. copy_exception name misleading 00189 /// Obtain an exception_ptr pointing to a copy of the supplied object. 00190 /// This function is deprecated, use std::make_exception_ptr instead. 00191 template<typename _Ex> 00192 exception_ptr 00193 copy_exception(_Ex __ex) _GLIBCXX_USE_NOEXCEPT _GLIBCXX_DEPRECATED; 00194 00195 template<typename _Ex> 00196 exception_ptr 00197 copy_exception(_Ex __ex) _GLIBCXX_USE_NOEXCEPT 00198 { return std::make_exception_ptr<_Ex>(__ex); } 00199 00200 // @} group exceptions 00201 } // namespace std 00202 00203 } // extern "C++" 00204 00205 #pragma GCC visibility pop 00206 00207 #endif