gcc/libstdc++-v3/libsupc++/nested_exception.h
Jason Merrill 20f2653ef0 PR c++/38796, Core issue 906
PR c++/38796, Core issue 906
gcc/cp
	* cp-tree.h (DECL_DEFAULTED_OUTSIDE_CLASS_P): New.
	(DECL_DEFAULTED_IN_CLASS_P): New.
	* class.c (user_provided_p): Non-static.
	(check_methods): Use it.
	(check_bases_and_members): Check defaulted fns.
	(defaultable_fn_p): Move and rename to...
	* method.c (defaultable_fn_check): ...this.
	(defaulted_late_check): New.
	* pt.c (tsubst_decl): Call it.
	* decl2.c (grokfield): Adjust.
	* decl.c (cp_finish_decl): Adjust.
	(grok_special_member_properties): Use user_provided_p.
libstdc++-v3
	* include/std/future (~Future_result_base): Default outside class
	body.
	* include/std/system_error (error_category()): Likewise.
	* libsupc++/nested_exception.h (nested_exception): Remove
	exception specifications from defaulted methods.

From-SVN: r153565
2009-10-26 15:07:14 -04:00

178 lines
4.5 KiB
C++

// 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&) = default;
nested_exception& operator=(const nested_exception&) = 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