// Implicitly construct an exception_wrapper from a qualifying exception.
// See the optimize struct for details.
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) {
- item_ = std::make_shared<Ex>(std::forward<Ex>(exn));
- throwfn_ = folly::detail::Thrower<Ex>::doThrow;
+ typedef typename std::decay<Ex>::type DEx;
+ 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
auto ew = make_exception_wrapper<std::runtime_error>("argh");
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());
+}