X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FExceptionWrapper.h;h=eb493fc68c10429428515a8f6459429e24d01162;hb=02fe20e3434fd6400ecf2ad92c7e1231b8f17108;hp=b00dc77d213a8e6e5efcf5d0187a4ccd3ca199a6;hpb=3c7ee0d0b0174c3d5cbe22581201c8fbef666bdf;p=folly.git diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index b00dc77d..eb493fc6 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -34,7 +34,9 @@ #include #include #include +#include #include +#include #ifdef __GNUC__ #pragma GCC diagnostic push @@ -42,8 +44,7 @@ #pragma GCC diagnostic ignored "-Wpotentially-evaluated-expression" // GCC gets confused about lambda scopes and issues shadow-local warnings for // parameters in totally different functions. -#pragma GCC diagnostic ignored "-Wshadow-local" -#pragma GCC diagnostic ignored "-Wshadow-compatible-local" +FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS #endif #define FOLLY_EXCEPTION_WRAPPER_H_INCLUDED @@ -196,7 +197,7 @@ class exception_wrapper final { exception_wrapper (*get_exception_ptr_)(exception_wrapper const*); }; - [[noreturn]] static void onNoExceptionError(); + [[noreturn]] static void onNoExceptionError(char const* name); template static Ret noop_(Args...); @@ -226,8 +227,8 @@ class exception_wrapper final { Buffer() : buff_{} {} - template >> - Buffer(in_place_t, Ex&& ex); + template + Buffer(in_place_type_t, As&&... as_); template Ex& as() noexcept; template @@ -258,8 +259,12 @@ class exception_wrapper final { "Surprise! std::exception and std::type_info don't have alignment " "greater than one. as_int_ below will not work!"); - static std::uintptr_t as_int_(std::exception const& e); - static std::uintptr_t as_int_(AnyException e); + static std::uintptr_t as_int_( + std::exception_ptr const& ptr, + std::exception const& e); + static std::uintptr_t as_int_( + std::exception_ptr const& ptr, + AnyException e); bool has_exception_() const; std::exception const* as_exception_() const; std::type_info const* as_type_() const; @@ -305,10 +310,10 @@ class exception_wrapper final { struct Impl final : public Base { Ex ex_; Impl() = default; - explicit Impl(Ex const& ex) : Base{typeid(ex)}, ex_(ex) {} - explicit Impl(Ex&& ex) - : Base{typeid(ex)}, - ex_(std::move(ex)){}[[noreturn]] void throw_() const override; + template + explicit Impl(As&&... as) + : Base{typeid(Ex)}, ex_(std::forward(as)...) {} + [[noreturn]] void throw_() const override; std::exception const* get_exception_() const noexcept override; exception_wrapper get_exception_ptr_() const noexcept override; }; @@ -331,11 +336,11 @@ class exception_wrapper final { }; VTable const* vptr_{&uninit_}; - template >> - exception_wrapper(Ex&& ex, OnHeapTag); + template + exception_wrapper(OnHeapTag, in_place_type_t, As&&... as); - template >> - exception_wrapper(Ex&& ex, InSituTag); + template + exception_wrapper(InSituTag, in_place_type_t, As&&... as); template struct IsRegularExceptionType @@ -363,6 +368,9 @@ class exception_wrapper final { static bool with_exception_(This& this_, Fn fn_); public: + static exception_wrapper from_exception_ptr( + std::exception_ptr const& eptr) noexcept; + //! Default-constructs an empty `exception_wrapper` //! \post `type() == none()` exception_wrapper() noexcept {} @@ -430,10 +438,16 @@ class exception_wrapper final { FOLLY_REQUIRES(IsRegularExceptionType::value)> exception_wrapper(in_place_t, Ex&& ex); + template < + class Ex, + typename... As, + FOLLY_REQUIRES(IsRegularExceptionType::value)> + exception_wrapper(in_place_type_t, As&&... as); + //! Swaps the value of `*this` with the value of `that` void swap(exception_wrapper& that) noexcept; - //! \return `true` if `*this` is not holding an exception. + //! \return `true` if `*this` is holding an exception. explicit operator bool() const noexcept; //! \return `!bool(*this)` @@ -594,7 +608,7 @@ constexpr exception_wrapper::VTable exception_wrapper::InPlace::ops_; */ template exception_wrapper make_exception_wrapper(As&&... as) { - return exception_wrapper{Ex{std::forward(as)...}}; + return exception_wrapper{in_place_type, std::forward(as)...}; } /** @@ -632,7 +646,7 @@ inline exception_wrapper try_and_catch_(F&& f) { return exception_wrapper(std::current_exception(), ex); } } -} // detail +} // namespace detail //! `try_and_catch` is a simple replacement for `try {} catch(){}`` that allows //! you to specify which derived exceptions you would like to catch and store in @@ -673,7 +687,7 @@ template exception_wrapper try_and_catch(F&& fn) { return detail::try_and_catch_(std::forward(fn)); } -} // folly +} // namespace folly #include