From: Eric Niebler Date: Thu, 4 May 2017 02:12:10 +0000 (-0700) Subject: test the typeid of the exception before it is potentially moved X-Git-Tag: v2017.05.08.00~12 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=5947e77818dae0a0409bbe0d577464f7b2a7a687 test the typeid of the exception before it is potentially moved Summary: Access the RTTI of the incomming exception before it is potentially moved from when testing for slicing Reviewed By: yfeldblum Differential Revision: D4999189 fbshipit-source-id: 3e6c0a9f10a27810484330e9b37a5b0ec450ff88 --- diff --git a/folly/ExceptionWrapper-inl.h b/folly/ExceptionWrapper-inl.h index d5ad7009..99cbd9de 100644 --- a/folly/ExceptionWrapper-inl.h +++ b/folly/ExceptionWrapper-inl.h @@ -287,6 +287,16 @@ inline exception_wrapper::exception_wrapper(std::exception_ptr ptr, Ex& ex) assert(eptr_.ptr_); } +namespace exception_wrapper_detail { +template +Ex&& dont_slice(Ex&& ex) { + assert(typeid(ex) == typeid(_t>) || + !"Dynamic and static exception types don't match. Exception would " + "be sliced when storing in exception_wrapper."); + return std::forward(ex); +} +} + template < class Ex, class Ex_, @@ -295,11 +305,9 @@ template < exception_wrapper::IsStdException, exception_wrapper::IsRegularExceptionType>::value)> inline exception_wrapper::exception_wrapper(Ex&& ex) - : exception_wrapper{std::forward(ex), PlacementOf{}} { - // Don't slice!!! - assert(typeid(ex) == typeid(Ex_) || - !"Dynamic and static exception types don't match. Exception would " - "be sliced when storing in exception_wrapper."); + : exception_wrapper{ + exception_wrapper_detail::dont_slice(std::forward(ex)), + PlacementOf{}} { } template < @@ -308,11 +316,9 @@ template < FOLLY_REQUIRES_DEF( exception_wrapper::IsRegularExceptionType::value)> inline exception_wrapper::exception_wrapper(in_place_t, Ex&& ex) - : exception_wrapper{std::forward(ex), PlacementOf{}} { - // Don't slice!!! - assert(typeid(ex) == typeid(Ex_) || - !"Dynamic and static exception types don't match. Exception would " - "be sliced when storing in exception_wrapper."); + : exception_wrapper{ + exception_wrapper_detail::dont_slice(std::forward(ex)), + PlacementOf{}} { } inline void exception_wrapper::swap(exception_wrapper& that) noexcept {