Commit c518e9ec authored by Misha Shneerson's avatar Misha Shneerson Committed by Facebook GitHub Bot

fix SharedPtr initialization

Summary: fix D21371986's sadness (SEGV  for `folly::make_exception<TException>().class_name()`)

Reviewed By: yfeldblum

Differential Revision: D21373766

fbshipit-source-id: 0dd951fd9393e73c5c38670167312c3d2e619fb5
parent 98419a68
...@@ -302,7 +302,7 @@ class exception_wrapper final { ...@@ -302,7 +302,7 @@ class exception_wrapper final {
struct SharedPtr { struct SharedPtr {
struct Base { struct Base {
std::type_info const* info_; std::type_info const* info_;
Base() = default; Base() = delete;
explicit Base(std::type_info const& info) : info_(&info) {} explicit Base(std::type_info const& info) : info_(&info) {}
virtual ~Base() {} virtual ~Base() {}
virtual void throw_() const = 0; virtual void throw_() const = 0;
...@@ -313,7 +313,7 @@ class exception_wrapper final { ...@@ -313,7 +313,7 @@ class exception_wrapper final {
struct Impl final : public Base { struct Impl final : public Base {
static_assert(IsStdException<Ex>::value, "only deriving std::exception"); static_assert(IsStdException<Ex>::value, "only deriving std::exception");
Ex ex_; Ex ex_;
Impl() = default; Impl() : Base{typeid(Ex)}, ex_() {}
// clang-format off // clang-format off
template <typename... As> template <typename... As>
explicit Impl(As&&... as) explicit Impl(As&&... as)
......
...@@ -546,6 +546,36 @@ TEST(ExceptionWrapper, base_derived_non_std_exception_test) { ...@@ -546,6 +546,36 @@ TEST(ExceptionWrapper, base_derived_non_std_exception_test) {
EXPECT_TRUE(ew.with_exception([](const DerivedException&) {})); EXPECT_TRUE(ew.with_exception([](const DerivedException&) {}));
} }
namespace {
struct ThrownException {};
struct InSituException : std::exception {
InSituException() = default;
InSituException(const InSituException&) throw() {}
};
struct OnHeapException : std::exception {
OnHeapException() = default;
OnHeapException(const OnHeapException&) {}
};
} // namespace
TEST(ExceptionWrapper, make_wrapper_no_args) {
EXPECT_TRUE(
folly::StringPiece(folly::make_exception_wrapper<ThrownException>()
.class_name()
.toStdString())
.endsWith("ThrownException"));
EXPECT_TRUE(
folly::StringPiece(folly::make_exception_wrapper<InSituException>()
.class_name()
.toStdString())
.endsWith("InSituException"));
EXPECT_TRUE(
folly::StringPiece(folly::make_exception_wrapper<OnHeapException>()
.class_name()
.toStdString())
.endsWith("OnHeapException"));
}
namespace { namespace {
// Cannot be stored within an exception_wrapper // Cannot be stored within an exception_wrapper
struct BigRuntimeError : std::runtime_error { struct BigRuntimeError : std::runtime_error {
......
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