exception_ptr.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // Exception Handling support header (exception_ptr class) for -*- C++ -*-
  2. // Copyright (C) 2008, 2009 Free Software Foundation
  3. //
  4. // This file is part of GCC.
  5. //
  6. // GCC is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation; either version 3, or (at your option)
  9. // any later version.
  10. //
  11. // GCC is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // Under Section 7 of GPL version 3, you are granted additional
  17. // permissions described in the GCC Runtime Library Exception, version
  18. // 3.1, as published by the Free Software Foundation.
  19. // You should have received a copy of the GNU General Public License and
  20. // a copy of the GCC Runtime Library Exception along with this program;
  21. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  22. // <http://www.gnu.org/licenses/>.
  23. /** @file exception_ptr.h
  24. * This is an internal header file, included by other headers and the
  25. * implementation. You should not attempt to use it directly.
  26. */
  27. #ifndef _EXCEPTION_PTR_H
  28. #define _EXCEPTION_PTR_H
  29. #pragma GCC visibility push(default)
  30. #include <bits/c++config.h>
  31. #include <exception_defines.h>
  32. #if !defined(_GLIBCXX_ATOMIC_BUILTINS_4)
  33. # error This platform does not support exception propagation.
  34. #endif
  35. extern "C++" {
  36. namespace std
  37. {
  38. /**
  39. * @addtogroup exceptions
  40. * @{
  41. */
  42. // Hide the free operators from other types
  43. namespace __exception_ptr
  44. {
  45. /**
  46. * @brief An opaque pointer to an arbitrary exception.
  47. */
  48. class exception_ptr;
  49. }
  50. using __exception_ptr::exception_ptr;
  51. /** Obtain an %exception_ptr to the currently handled exception. If there
  52. * is none, or the currently handled exception is foreign, return the null
  53. * value.
  54. */
  55. exception_ptr current_exception() throw();
  56. /// Throw the object pointed to by the %exception_ptr.
  57. void rethrow_exception(exception_ptr) __attribute__ ((__noreturn__));
  58. /// Obtain an %exception_ptr pointing to a copy of the supplied object.
  59. template<typename _Ex>
  60. exception_ptr
  61. copy_exception(_Ex __ex) throw();
  62. namespace __exception_ptr
  63. {
  64. bool
  65. operator==(const exception_ptr&, const exception_ptr&) throw();
  66. bool
  67. operator!=(const exception_ptr&, const exception_ptr&) throw();
  68. class exception_ptr
  69. {
  70. void* _M_exception_object;
  71. explicit exception_ptr(void* __e) throw();
  72. void _M_addref() throw();
  73. void _M_release() throw();
  74. void *_M_get() const throw();
  75. void _M_safe_bool_dummy();
  76. friend exception_ptr std::current_exception() throw();
  77. friend void std::rethrow_exception(exception_ptr);
  78. public:
  79. exception_ptr() throw();
  80. typedef void (exception_ptr::*__safe_bool)();
  81. // For construction from nullptr or 0.
  82. exception_ptr(__safe_bool) throw();
  83. exception_ptr(const exception_ptr&) throw();
  84. #ifdef __GXX_EXPERIMENTAL_CXX0X__
  85. exception_ptr(exception_ptr&& __o) throw()
  86. : _M_exception_object(__o._M_exception_object)
  87. { __o._M_exception_object = 0; }
  88. #endif
  89. exception_ptr&
  90. operator=(const exception_ptr&) throw();
  91. #ifdef __GXX_EXPERIMENTAL_CXX0X__
  92. exception_ptr&
  93. operator=(exception_ptr&& __o) throw()
  94. {
  95. exception_ptr(static_cast<exception_ptr&&>(__o)).swap(*this);
  96. return *this;
  97. }
  98. #endif
  99. ~exception_ptr() throw();
  100. void
  101. swap(exception_ptr&) throw();
  102. #ifdef _GLIBCXX_EH_PTR_COMPAT
  103. // Retained for compatibility with CXXABI_1.3.
  104. bool operator!() const throw();
  105. operator __safe_bool() const throw();
  106. #endif
  107. friend bool
  108. operator==(const exception_ptr&, const exception_ptr&) throw();
  109. const type_info*
  110. __cxa_exception_type() const throw();
  111. };
  112. } // namespace __exception_ptr
  113. template<typename _Ex>
  114. exception_ptr
  115. copy_exception(_Ex __ex) throw()
  116. {
  117. __try
  118. {
  119. throw __ex;
  120. }
  121. __catch(...)
  122. {
  123. return current_exception ();
  124. }
  125. }
  126. // @} group exceptions
  127. } // namespace std
  128. } // extern "C++"
  129. #pragma GCC visibility pop
  130. #endif