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