From 66503ecccd41260d9d73cbae89cef1f73addd0d4 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Fri, 17 Jan 2020 13:04:30 -0800 Subject: [PATCH] crimson/common/errorator: restrict all_same_way to valid types As with pass_further/discard_all, we don't want the returned handler to work on types outside of the errorator at all. Otherwise, the handler will transparently apply to any error. Signed-off-by: Samuel Just --- src/crimson/common/errorator.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/crimson/common/errorator.h b/src/crimson/common/errorator.h index 3750b67360a50..b57c8407e5cee 100644 --- a/src/crimson/common/errorator.h +++ b/src/crimson/common/errorator.h @@ -635,6 +635,21 @@ private: template using EnableIf = typename std::enable_if>, Enabler>::type; + template + struct all_same_way_t { + ErrorFunc func; + all_same_way_t(ErrorFunc &&error_func) + : func(std::forward(error_func)) {} + + template ...> + decltype(auto) operator()(ErrorT&& e) { + using decayed_t = std::decay_t; + auto&& handler = + decayed_t::error_t::handle(std::forward(func)); + return std::invoke(std::move(handler), std::forward(e)); + } + }; + public: // HACK: `errorated_future_marker` and `_future` is just a hack to // specialize `seastar::futurize` for category of class templates: @@ -667,14 +682,7 @@ public: template static decltype(auto) all_same_way(ErrorFunc&& error_func) { - return [ - error_func = std::forward(error_func) - ] (auto&& e) mutable -> decltype(auto) { - using decayed_t = std::decay_t; - auto&& handler = - decayed_t::error_t::handle(std::forward(error_func)); - return std::invoke(std::move(handler), std::forward(e)); - }; + return all_same_way_t{std::forward(error_func)}; }; // get a new errorator by extending current one with new error -- 2.39.5