aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/libsupc++
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely.gcc@gmail.com>2009-05-12 21:08:00 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2009-05-12 22:08:00 +0100
commit182da14a6284aab605f6eace40c80325802b2b15 (patch)
tree6d3c52a09911d5143b7a7fe3511fbe5e9ec350b4 /libstdc++-v3/libsupc++
parent704bf7c8ae47f7d609d5236d4d61e588bd595dee (diff)
downloadgcc-182da14a6284aab605f6eace40c80325802b2b15.zip
gcc-182da14a6284aab605f6eace40c80325802b2b15.tar.gz
gcc-182da14a6284aab605f6eace40c80325802b2b15.tar.bz2
exception: Include nested_exception.h in C++0x mode.
2009-05-12 Jonathan Wakely <jwakely.gcc@gmail.com> * libsupc++/exception: Include nested_exception.h in C++0x mode. * libsupc++/nested_exception.h: New. * libsupc++/Makefile.am: Add new header. * libsupc++/Makefile.in: Regenerate. * testsuite/18_support/nested_exception/rethrow_nested.cc: New. * testsuite/18_support/nested_exception/throw_with_nested.cc: New. * testsuite/18_support/nested_exception/cons.cc: New. * testsuite/18_support/nested_exception/nested_ptr.cc: New. * testsuite/18_support/nested_exception/rethrow_if_nested.cc: New. * doc/xml/manual/status_cxx200x.xml: Adjust. From-SVN: r147446
Diffstat (limited to 'libstdc++-v3/libsupc++')
-rw-r--r--libstdc++-v3/libsupc++/Makefile.am2
-rw-r--r--libstdc++-v3/libsupc++/Makefile.in2
-rw-r--r--libstdc++-v3/libsupc++/exception1
-rw-r--r--libstdc++-v3/libsupc++/nested_exception.h177
4 files changed, 180 insertions, 2 deletions
diff --git a/libstdc++-v3/libsupc++/Makefile.am b/libstdc++-v3/libsupc++/Makefile.am
index 5c86a1e..b84b5e4 100644
--- a/libstdc++-v3/libsupc++/Makefile.am
+++ b/libstdc++-v3/libsupc++/Makefile.am
@@ -33,7 +33,7 @@ noinst_LTLIBRARIES = libsupc++convenience.la
headers = \
exception new typeinfo cxxabi.h cxxabi-forced.h exception_defines.h \
- initializer_list exception_ptr.h
+ initializer_list exception_ptr.h nested_exception.h
if GLIBCXX_HOSTED
c_sources = \
diff --git a/libstdc++-v3/libsupc++/Makefile.in b/libstdc++-v3/libsupc++/Makefile.in
index 26fbd54..50ede6a 100644
--- a/libstdc++-v3/libsupc++/Makefile.in
+++ b/libstdc++-v3/libsupc++/Makefile.in
@@ -367,7 +367,7 @@ toolexeclib_LTLIBRARIES = libsupc++.la
noinst_LTLIBRARIES = libsupc++convenience.la
headers = \
exception new typeinfo cxxabi.h cxxabi-forced.h exception_defines.h \
- initializer_list exception_ptr.h
+ initializer_list exception_ptr.h nested_exception.h
@GLIBCXX_HOSTED_TRUE@c_sources = \
@GLIBCXX_HOSTED_TRUE@ cp-demangle.c
diff --git a/libstdc++-v3/libsupc++/exception b/libstdc++-v3/libsupc++/exception
index c8b334f..be7dec6 100644
--- a/libstdc++-v3/libsupc++/exception
+++ b/libstdc++-v3/libsupc++/exception
@@ -146,6 +146,7 @@ _GLIBCXX_END_NAMESPACE
#if (defined(__GXX_EXPERIMENTAL_CXX0X__) \
&& defined(_GLIBCXX_ATOMIC_BUILTINS_4))
#include <exception_ptr.h>
+#include <nested_exception.h>
#endif
#endif
diff --git a/libstdc++-v3/libsupc++/nested_exception.h b/libstdc++-v3/libsupc++/nested_exception.h
new file mode 100644
index 0000000..752c595
--- /dev/null
+++ b/libstdc++-v3/libsupc++/nested_exception.h
@@ -0,0 +1,177 @@
+// Nested Exception support header (nested_exception class) for -*- C++ -*-
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file nested_exception.h
+ * This is an internal header file, included by other headers and the
+ * implementation. You should not attempt to use it directly.
+ */
+
+#ifndef _GLIBCXX_NESTED_EXCEPTION_H
+#define _GLIBCXX_NESTED_EXCEPTION_H 1
+
+#pragma GCC visibility push(default)
+
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
+# include <c++0x_warning.h>
+#else
+
+#include <bits/c++config.h>
+
+#if !defined(_GLIBCXX_ATOMIC_BUILTINS_4)
+# error This platform does not support exception propagation.
+#endif
+
+extern "C++" {
+
+namespace std
+{
+ /**
+ * @addtogroup exceptions
+ * @{
+ */
+
+ /// nested_exception
+ class nested_exception
+ {
+ public:
+ nested_exception() throw() : _M_ptr(current_exception()) { }
+
+ nested_exception(const nested_exception&) throw() = default;
+
+ nested_exception& operator=(const nested_exception&) throw() = default;
+
+ virtual ~nested_exception() = default;
+
+ void
+ rethrow_nested() const __attribute__ ((__noreturn__))
+ { rethrow_exception(_M_ptr); }
+
+ exception_ptr
+ nested_ptr() const
+ { return _M_ptr; }
+
+ private:
+ exception_ptr _M_ptr;
+ };
+
+ template<typename _Except>
+ struct _Nested_exception : public _Except, public nested_exception
+ {
+ explicit
+ _Nested_exception(_Except&& __ex)
+ : _Except(static_cast<_Except&&>(__ex))
+ { }
+ };
+
+ template<typename _Ex>
+ struct __get_nested_helper
+ {
+ static const nested_exception*
+ _S_get(const _Ex& __ex)
+ {
+ return dynamic_cast<const nested_exception*>(&__ex);
+ }
+ };
+
+ template<typename _Ex>
+ struct __get_nested_helper<_Ex*>
+ {
+ static const nested_exception*
+ _S_get(const _Ex* __ex)
+ {
+ return dynamic_cast<const nested_exception*>(__ex);
+ }
+ };
+
+ template<typename _Ex>
+ inline const nested_exception*
+ __get_nested_exception(const _Ex& __ex)
+ {
+ return __get_nested_helper<_Ex>::_S_get(__ex);
+ }
+
+ template<typename _Ex>
+ void
+ __throw_with_nested(_Ex&&, const nested_exception* = 0)
+ __attribute__ ((__noreturn__));
+
+ template<typename _Ex>
+ void
+ __throw_with_nested(_Ex&&, ...) __attribute__ ((__noreturn__));
+
+ // This function should never be called, but is needed to avoid a warning
+ // about ambiguous base classes when instantiating throw_with_nested<_Ex>()
+ // with a type that has an accessible nested_exception base.
+ template<typename _Ex>
+ inline void
+ __throw_with_nested(_Ex&& __ex, const nested_exception* = 0)
+ {
+ throw __ex;
+ }
+
+ template<typename _Ex>
+ inline void
+ __throw_with_nested(_Ex&& __ex, ...)
+ {
+ throw _Nested_exception<_Ex>(static_cast<_Ex&&>(__ex));
+ }
+
+ template<typename _Ex>
+ void
+ throw_with_nested(_Ex __ex) __attribute__ ((__noreturn__));
+
+ template<typename _Ex>
+ inline void
+ throw_with_nested(_Ex __ex)
+ {
+ if (__get_nested_exception(__ex))
+ throw __ex;
+ __throw_with_nested(static_cast<_Ex&&>(__ex), &__ex);
+ }
+
+ template<typename _Ex>
+ inline void
+ rethrow_if_nested(const _Ex& __ex)
+ {
+ if (const nested_exception* __nested = __get_nested_exception(__ex))
+ __nested->rethrow_nested();
+ }
+
+ // see n2619
+ inline void
+ rethrow_if_nested(const nested_exception& __ex)
+ {
+ __ex.rethrow_nested();
+ }
+
+ // @} group exceptions
+} // namespace std
+
+} // extern "C++"
+
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+
+#pragma GCC visibility pop
+
+#endif // _GLIBCXX_NESTED_EXCEPTION_H