From bf87ffac83b2a36aadbb4bb3c106b36258c06a20 Mon Sep 17 00:00:00 2001 From: Tudor Bosman Date: Fri, 12 Jun 2015 16:57:02 -0700 Subject: [PATCH] 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 --- folly/ExceptionWrapper.h | 8 +++++--- folly/test/ExceptionWrapperTest.cpp | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index a99e84d9..bfe19a03 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -112,10 +112,12 @@ class exception_wrapper { // Implicitly construct an exception_wrapper from a qualifying exception. // See the optimize struct for details. template ::value>::type> + typename std::enable_if::type>::value> + ::type> /* implicit */ exception_wrapper(Ex&& exn) { - item_ = std::make_shared(std::forward(exn)); - throwfn_ = folly::detail::Thrower::doThrow; + typedef typename std::decay::type DEx; + item_ = std::make_shared(std::forward(exn)); + throwfn_ = folly::detail::Thrower::doThrow; } // The following two constructors are meant to emulate the behavior of diff --git a/folly/test/ExceptionWrapperTest.cpp b/folly/test/ExceptionWrapperTest.cpp index a12445ad..47b18d2e 100644 --- a/folly/test/ExceptionWrapperTest.cpp +++ b/folly/test/ExceptionWrapperTest.cpp @@ -227,3 +227,17 @@ TEST(ExceptionWrapper, exceptionStr) { auto ew = make_exception_wrapper("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()); +} -- 2.34.1