Commit bf87ffac authored by Tudor Bosman's avatar Tudor Bosman Committed by Sara Golemon

ExceptionWrapper: use std::decay in implicit constructor

Summary: Because Ex resolves to SomeException&, and then all the tests in optimize<>
fail.

Reviewed By: @yfeldblum

Differential Revision: D2152893
parent ae93c76d
...@@ -112,10 +112,12 @@ class exception_wrapper { ...@@ -112,10 +112,12 @@ class exception_wrapper {
// Implicitly construct an exception_wrapper from a qualifying exception. // Implicitly construct an exception_wrapper from a qualifying exception.
// See the optimize struct for details. // See the optimize struct for details.
template <typename Ex, typename = template <typename Ex, typename =
typename std::enable_if<optimize<Ex>::value>::type> typename std::enable_if<optimize<typename std::decay<Ex>::type>::value>
::type>
/* implicit */ exception_wrapper(Ex&& exn) { /* implicit */ exception_wrapper(Ex&& exn) {
item_ = std::make_shared<Ex>(std::forward<Ex>(exn)); typedef typename std::decay<Ex>::type DEx;
throwfn_ = folly::detail::Thrower<Ex>::doThrow; item_ = std::make_shared<DEx>(std::forward<Ex>(exn));
throwfn_ = folly::detail::Thrower<DEx>::doThrow;
} }
// The following two constructors are meant to emulate the behavior of // The following two constructors are meant to emulate the behavior of
......
...@@ -227,3 +227,17 @@ TEST(ExceptionWrapper, exceptionStr) { ...@@ -227,3 +227,17 @@ TEST(ExceptionWrapper, exceptionStr) {
auto ew = make_exception_wrapper<std::runtime_error>("argh"); auto ew = make_exception_wrapper<std::runtime_error>("argh");
EXPECT_EQ("std::runtime_error: argh", exceptionStr(ew)); EXPECT_EQ("std::runtime_error: argh", exceptionStr(ew));
} }
namespace {
class TestException : public std::exception { };
void testEW(const exception_wrapper& ew) {
EXPECT_THROW(ew.throwException(), TestException);
}
} // namespace
TEST(ExceptionWrapper, implicitConstruction) {
// Try with both lvalue and rvalue references
TestException e;
testEW(e);
testEW(TestException());
}
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