diff --git a/libcxx/include/__exception/nested_exception.h b/libcxx/include/__exception/nested_exception.h index 1bf2df939258a6..feb489f87f62f5 100644 --- a/libcxx/include/__exception/nested_exception.h +++ b/libcxx/include/__exception/nested_exception.h @@ -84,17 +84,15 @@ struct __can_dynamic_cast : _BoolConstant< is_polymorphic<_From>::value && (!is_base_of<_To, _From>::value || is_convertible::value)> {}; -template -inline _LIBCPP_HIDE_FROM_ABI void -rethrow_if_nested(const _Ep& __e, __enable_if_t< __can_dynamic_cast<_Ep, nested_exception>::value>* = 0) { +template ::value, int> = 0> +inline _LIBCPP_HIDE_FROM_ABI void rethrow_if_nested(const _Ep& __e) { const nested_exception* __nep = dynamic_cast(std::addressof(__e)); if (__nep) __nep->rethrow_nested(); } -template -inline _LIBCPP_HIDE_FROM_ABI void -rethrow_if_nested(const _Ep&, __enable_if_t::value>* = 0) {} +template ::value, int> = 0> +inline _LIBCPP_HIDE_FROM_ABI void rethrow_if_nested(const _Ep&) {} } // namespace std diff --git a/libcxx/test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp b/libcxx/test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp index 39bf62b8193bb4..30ce86f5277b04 100644 --- a/libcxx/test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp +++ b/libcxx/test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp @@ -18,8 +18,10 @@ // template void rethrow_if_nested(const E& e); #include +#include #include #include +#include #include "test_macros.h" @@ -58,6 +60,31 @@ class E1 : public std::nested_exception {}; class E2 : public std::nested_exception {}; class E : public E1, public E2 {}; +#if TEST_STD_VER >= 11 +template +struct can_rethrow_if_nested_impl { + static constexpr bool value = false; +}; + +template +struct can_rethrow_if_nested_impl()...)), Args...> { + static constexpr bool value = true; +}; + +template +struct can_rethrow_if_nested : can_rethrow_if_nested_impl {}; + +static_assert(!can_rethrow_if_nested<>::value, ""); +static_assert(can_rethrow_if_nested::value, ""); +static_assert(can_rethrow_if_nested::value, ""); +static_assert(can_rethrow_if_nested::value, ""); +static_assert(can_rethrow_if_nested::value, ""); +static_assert(!can_rethrow_if_nested::value, ""); +static_assert(!can_rethrow_if_nested::value, ""); +static_assert(!can_rethrow_if_nested::value, ""); +static_assert(!can_rethrow_if_nested::value, ""); +#endif + int main(int, char**) { {