From 9ac5bc55962461645e741c64fba3b0c85cd3b8b3 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 13 Apr 2017 14:41:45 +0000 Subject: [PATCH] Refactor throw_with_nested. NFC. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@300197 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/exception | 70 ++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/include/exception b/include/exception index 216ae0c70..b12a4c2b2 100644 --- a/include/exception +++ b/include/exception @@ -202,46 +202,54 @@ struct __nested _LIBCPP_INLINE_VISIBILITY explicit __nested(const _Tp& __t) : _Tp(__t) {} }; -template -_LIBCPP_NORETURN -void -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -throw_with_nested(_Tp&& __t, typename enable_if< - is_class::type>::value && - !is_base_of::type>::value - && !__libcpp_is_final::type>::value - >::type* = 0) -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES -throw_with_nested (_Tp& __t, typename enable_if< - is_class<_Tp>::value && !is_base_of::value - >::type* = 0) -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -{ #ifndef _LIBCPP_NO_EXCEPTIONS - throw __nested::type>(_VSTD::forward<_Tp>(__t)); -#else - ((void)__t); - // FIXME: Make this abort. +template +struct __throw_with_nested; + +template +struct __throw_with_nested<_Tp, _Up, true> { + _LIBCPP_NORETURN static inline _LIBCPP_ALWAYS_INLINE void + #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + __do_throw(_Tp&& __t) + #else + __do_throw (_Tp& __t) + #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + throw __nested<_Up>(_VSTD::forward<_Tp>(__t)); + } +}; + +template +struct __throw_with_nested<_Tp, _Up, false> { + _LIBCPP_NORETURN static inline _LIBCPP_ALWAYS_INLINE void + #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + __do_throw(_Tp&& __t) + #else + __do_throw (_Tp& __t) + #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + throw _VSTD::forward<_Tp>(__t); + } +}; #endif -} template _LIBCPP_NORETURN void #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -throw_with_nested(_Tp&& __t, typename enable_if< - !is_class::type>::value || - is_base_of::type>::value - || __libcpp_is_final::type>::value - >::type* = 0) -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES -throw_with_nested (_Tp& __t, typename enable_if< - !is_class<_Tp>::value || is_base_of::value - >::type* = 0) -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +throw_with_nested(_Tp&& __t) +#else +throw_with_nested (_Tp& __t) +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES { #ifndef _LIBCPP_NO_EXCEPTIONS - throw _VSTD::forward<_Tp>(__t); + typedef typename remove_reference<_Tp>::type _Up; +// static_assert( is_copy_constructible<_Up>::value, ""); + __throw_with_nested<_Tp, _Up, + is_class<_Up>::value && + !is_base_of::value && + !__libcpp_is_final<_Up>::value>:: + __do_throw(_VSTD::forward<_Tp>(__t)); #else ((void)__t); // FIXME: Make this abort