From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- libstdc++-v3/libsupc++/nested_exception.h | 166 ++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 libstdc++-v3/libsupc++/nested_exception.h (limited to 'libstdc++-v3/libsupc++/nested_exception.h') diff --git a/libstdc++-v3/libsupc++/nested_exception.h b/libstdc++-v3/libsupc++/nested_exception.h new file mode 100644 index 000000000..d4804bbed --- /dev/null +++ b/libstdc++-v3/libsupc++/nested_exception.h @@ -0,0 +1,166 @@ +// Nested Exception support header (nested_exception class) for -*- C++ -*- + +// Copyright (C) 2009, 2010, 2011 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 +// . + +/** @file bits/nested_exception.h + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{exception} + */ + +#ifndef _GLIBCXX_NESTED_EXCEPTION_H +#define _GLIBCXX_NESTED_EXCEPTION_H 1 + +#pragma GCC visibility push(default) + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +# include +#else + +#include + +#if !defined(_GLIBCXX_ATOMIC_BUILTINS_4) +# error This platform does not support exception propagation. +#endif + +extern "C++" { + +namespace std +{ + /** + * @addtogroup exceptions + * @{ + */ + + /// Exception class with exception_ptr data member. + class nested_exception + { + exception_ptr _M_ptr; + + public: + nested_exception() throw() : _M_ptr(current_exception()) { } + + nested_exception(const nested_exception&) = default; + + nested_exception& operator=(const nested_exception&) = default; + + virtual ~nested_exception(); + + void + rethrow_nested() const __attribute__ ((__noreturn__)) + { rethrow_exception(_M_ptr); } + + exception_ptr + nested_ptr() const + { return _M_ptr; } + }; + + template + struct _Nested_exception : public _Except, public nested_exception + { + explicit _Nested_exception(_Except&& __ex) + : _Except(static_cast<_Except&&>(__ex)) + { } + }; + + template + struct __get_nested_helper + { + static const nested_exception* + _S_get(const _Ex& __ex) + { return dynamic_cast(&__ex); } + }; + + template + struct __get_nested_helper<_Ex*> + { + static const nested_exception* + _S_get(const _Ex* __ex) + { return dynamic_cast(__ex); } + }; + + template + inline const nested_exception* + __get_nested_exception(const _Ex& __ex) + { return __get_nested_helper<_Ex>::_S_get(__ex); } + + template + void + __throw_with_nested(_Ex&&, const nested_exception* = 0) + __attribute__ ((__noreturn__)); + + template + 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 + inline void + __throw_with_nested(_Ex&& __ex, const nested_exception*) + { throw __ex; } + + template + inline void + __throw_with_nested(_Ex&& __ex, ...) + { throw _Nested_exception<_Ex>(static_cast<_Ex&&>(__ex)); } + + template + void + throw_with_nested(_Ex __ex) __attribute__ ((__noreturn__)); + + /// If @p __ex is derived from nested_exception, @p __ex. + /// Else, an implementation-defined object derived from both. + template + inline void + throw_with_nested(_Ex __ex) + { + if (__get_nested_exception(__ex)) + throw __ex; + __throw_with_nested(static_cast<_Ex&&>(__ex), &__ex); + } + + /// If @p __ex is derived from nested_exception, @p __ex.rethrow_nested(). + template + inline void + rethrow_if_nested(const _Ex& __ex) + { + if (const nested_exception* __nested = __get_nested_exception(__ex)) + __nested->rethrow_nested(); + } + + /// Overload, 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 -- cgit v1.2.3