libstdc++
exception_ptr.h
Go to the documentation of this file.
1 // Exception Handling support header (exception_ptr class) for -*- C++ -*-
2 
3 // Copyright (C) 2008-2015 Free Software Foundation, Inc.
4 //
5 // This file is part of GCC.
6 //
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)
10 // any later version.
11 //
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.
16 //
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.
20 
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/>.
25 
26 /** @file bits/exception_ptr.h
27  * This is an internal header file, included by other library headers.
28  * Do not attempt to use it directly. @headername{exception}
29  */
30 
31 #ifndef _EXCEPTION_PTR_H
32 #define _EXCEPTION_PTR_H
33 
34 #pragma GCC visibility push(default)
35 
36 #include <bits/c++config.h>
37 #include <bits/exception_defines.h>
38 
39 extern "C++" {
40 
41 namespace std
42 {
43  class type_info;
44 
45  /**
46  * @addtogroup exceptions
47  * @{
48  */
49  namespace __exception_ptr
50  {
51  class exception_ptr;
52  }
53 
54  using __exception_ptr::exception_ptr;
55 
56  /** Obtain an exception_ptr to the currently handled exception. If there
57  * is none, or the currently handled exception is foreign, return the null
58  * value.
59  */
60  exception_ptr current_exception() _GLIBCXX_USE_NOEXCEPT;
61 
62  /// Throw the object pointed to by the exception_ptr.
63  void rethrow_exception(exception_ptr) __attribute__ ((__noreturn__));
64 
65  namespace __exception_ptr
66  {
67  /**
68  * @brief An opaque pointer to an arbitrary exception.
69  * @ingroup exceptions
70  */
72  {
73  void* _M_exception_object;
74 
75  explicit exception_ptr(void* __e) _GLIBCXX_USE_NOEXCEPT;
76 
77  void _M_addref() _GLIBCXX_USE_NOEXCEPT;
78  void _M_release() _GLIBCXX_USE_NOEXCEPT;
79 
80  void *_M_get() const _GLIBCXX_NOEXCEPT __attribute__ ((__pure__));
81 
82  friend exception_ptr std::current_exception() _GLIBCXX_USE_NOEXCEPT;
84 
85  public:
86  exception_ptr() _GLIBCXX_USE_NOEXCEPT;
87 
88  exception_ptr(const exception_ptr&) _GLIBCXX_USE_NOEXCEPT;
89 
90 #if __cplusplus >= 201103L
91  exception_ptr(nullptr_t) noexcept
92  : _M_exception_object(0)
93  { }
94 
95  exception_ptr(exception_ptr&& __o) noexcept
96  : _M_exception_object(__o._M_exception_object)
97  { __o._M_exception_object = 0; }
98 #endif
99 
100 #if (__cplusplus < 201103L) || defined (_GLIBCXX_EH_PTR_COMPAT)
101  typedef void (exception_ptr::*__safe_bool)();
102 
103  // For construction from nullptr or 0.
104  exception_ptr(__safe_bool) _GLIBCXX_USE_NOEXCEPT;
105 #endif
106 
107  exception_ptr&
108  operator=(const exception_ptr&) _GLIBCXX_USE_NOEXCEPT;
109 
110 #if __cplusplus >= 201103L
111  exception_ptr&
112  operator=(exception_ptr&& __o) noexcept
113  {
114  exception_ptr(static_cast<exception_ptr&&>(__o)).swap(*this);
115  return *this;
116  }
117 #endif
118 
119  ~exception_ptr() _GLIBCXX_USE_NOEXCEPT;
120 
121  void
122  swap(exception_ptr&) _GLIBCXX_USE_NOEXCEPT;
123 
124 #ifdef _GLIBCXX_EH_PTR_COMPAT
125  // Retained for compatibility with CXXABI_1.3.
126  void _M_safe_bool_dummy() _GLIBCXX_USE_NOEXCEPT
127  __attribute__ ((__const__));
128  bool operator!() const _GLIBCXX_USE_NOEXCEPT
129  __attribute__ ((__pure__));
130  operator __safe_bool() const _GLIBCXX_USE_NOEXCEPT;
131 #endif
132 
133 #if __cplusplus >= 201103L
134  explicit operator bool() const
135  { return _M_exception_object; }
136 #endif
137 
138  friend bool
139  operator==(const exception_ptr&, const exception_ptr&)
140  _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__));
141 
142  const class std::type_info*
143  __cxa_exception_type() const _GLIBCXX_USE_NOEXCEPT
144  __attribute__ ((__pure__));
145  };
146 
147  bool
148  operator==(const exception_ptr&, const exception_ptr&)
149  _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__));
150 
151  bool
152  operator!=(const exception_ptr&, const exception_ptr&)
153  _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__));
154 
155  inline void
156  swap(exception_ptr& __lhs, exception_ptr& __rhs)
157  { __lhs.swap(__rhs); }
158 
159  } // namespace __exception_ptr
160 
161 
162  /// Obtain an exception_ptr pointing to a copy of the supplied object.
163  template<typename _Ex>
165  make_exception_ptr(_Ex __ex) _GLIBCXX_USE_NOEXCEPT
166  {
167 #if __cpp_exceptions
168  try
169  {
170  throw __ex;
171  }
172  catch(...)
173  {
174  return current_exception();
175  }
176 #else
177  return exception_ptr();
178 #endif
179  }
180 
181  // _GLIBCXX_RESOLVE_LIB_DEFECTS
182  // 1130. copy_exception name misleading
183  /// Obtain an exception_ptr pointing to a copy of the supplied object.
184  /// This function is deprecated, use std::make_exception_ptr instead.
185  template<typename _Ex>
187  copy_exception(_Ex __ex) _GLIBCXX_USE_NOEXCEPT _GLIBCXX_DEPRECATED;
188 
189  template<typename _Ex>
191  copy_exception(_Ex __ex) _GLIBCXX_USE_NOEXCEPT
192  { return std::make_exception_ptr<_Ex>(__ex); }
193 
194  // @} group exceptions
195 } // namespace std
196 
197 } // extern "C++"
198 
199 #pragma GCC visibility pop
200 
201 #endif
void rethrow_exception(exception_ptr) __attribute__((__noreturn__))
Throw the object pointed to by the exception_ptr.
exception_ptr copy_exception(_Ex __ex) noexcept 1
Obtain an exception_ptr pointing to a copy of the supplied object. This function is deprecated...
An opaque pointer to an arbitrary exception.
Definition: exception_ptr.h:71
ISO C++ entities toplevel namespace is std.
exception_ptr current_exception() noexcept
Part of RTTI.
Definition: typeinfo:88
exception_ptr make_exception_ptr(_Ex __ex) noexcept
Obtain an exception_ptr pointing to a copy of the supplied object.