Commit 5947e778 authored by Eric Niebler's avatar Eric Niebler Committed by Facebook Github Bot

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
parent 919d544e
...@@ -287,6 +287,16 @@ inline exception_wrapper::exception_wrapper(std::exception_ptr ptr, Ex& ex) ...@@ -287,6 +287,16 @@ inline exception_wrapper::exception_wrapper(std::exception_ptr ptr, Ex& ex)
assert(eptr_.ptr_); assert(eptr_.ptr_);
} }
namespace exception_wrapper_detail {
template <class Ex>
Ex&& dont_slice(Ex&& ex) {
assert(typeid(ex) == typeid(_t<std::decay<Ex>>) ||
!"Dynamic and static exception types don't match. Exception would "
"be sliced when storing in exception_wrapper.");
return std::forward<Ex>(ex);
}
}
template < template <
class Ex, class Ex,
class Ex_, class Ex_,
...@@ -295,11 +305,9 @@ template < ...@@ -295,11 +305,9 @@ template <
exception_wrapper::IsStdException<Ex_>, exception_wrapper::IsStdException<Ex_>,
exception_wrapper::IsRegularExceptionType<Ex_>>::value)> exception_wrapper::IsRegularExceptionType<Ex_>>::value)>
inline exception_wrapper::exception_wrapper(Ex&& ex) inline exception_wrapper::exception_wrapper(Ex&& ex)
: exception_wrapper{std::forward<Ex>(ex), PlacementOf<Ex_>{}} { : exception_wrapper{
// Don't slice!!! exception_wrapper_detail::dont_slice(std::forward<Ex>(ex)),
assert(typeid(ex) == typeid(Ex_) || PlacementOf<Ex_>{}} {
!"Dynamic and static exception types don't match. Exception would "
"be sliced when storing in exception_wrapper.");
} }
template < template <
...@@ -308,11 +316,9 @@ template < ...@@ -308,11 +316,9 @@ template <
FOLLY_REQUIRES_DEF( FOLLY_REQUIRES_DEF(
exception_wrapper::IsRegularExceptionType<Ex_>::value)> exception_wrapper::IsRegularExceptionType<Ex_>::value)>
inline exception_wrapper::exception_wrapper(in_place_t, Ex&& ex) inline exception_wrapper::exception_wrapper(in_place_t, Ex&& ex)
: exception_wrapper{std::forward<Ex>(ex), PlacementOf<Ex_>{}} { : exception_wrapper{
// Don't slice!!! exception_wrapper_detail::dont_slice(std::forward<Ex>(ex)),
assert(typeid(ex) == typeid(Ex_) || PlacementOf<Ex_>{}} {
!"Dynamic and static exception types don't match. Exception would "
"be sliced when storing in exception_wrapper.");
} }
inline void exception_wrapper::swap(exception_wrapper& that) noexcept { inline void exception_wrapper::swap(exception_wrapper& that) noexcept {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment