]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/common/errorator: restrict all_same_way to valid types 33344/head
authorSamuel Just <sjust@redhat.com>
Fri, 17 Jan 2020 21:04:30 +0000 (13:04 -0800)
committerSamuel Just <sjust@redhat.com>
Sat, 15 Feb 2020 01:28:38 +0000 (17:28 -0800)
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 <sjust@redhat.com>
src/crimson/common/errorator.h

index 3750b67360a50a004524752dd2cc51d0e93c1986..b57c8407e5ceede0ecf8f3685f6842bba12a52a6 100644 (file)
@@ -635,6 +635,21 @@ private:
   template <typename T>
   using EnableIf = typename std::enable_if<contains_once_v<std::decay_t<T>>, Enabler>::type;
 
+  template <typename ErrorFunc>
+  struct all_same_way_t {
+    ErrorFunc func;
+    all_same_way_t(ErrorFunc &&error_func)
+      : func(std::forward<ErrorFunc>(error_func)) {}
+
+    template <typename ErrorT, EnableIf<ErrorT>...>
+    decltype(auto) operator()(ErrorT&& e) {
+      using decayed_t = std::decay_t<decltype(e)>;
+      auto&& handler =
+        decayed_t::error_t::handle(std::forward<ErrorFunc>(func));
+      return std::invoke(std::move(handler), std::forward<ErrorT>(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 <class ErrorFunc>
   static decltype(auto) all_same_way(ErrorFunc&& error_func) {
-    return [
-      error_func = std::forward<ErrorFunc>(error_func)
-    ] (auto&& e) mutable -> decltype(auto) {
-      using decayed_t = std::decay_t<decltype(e)>;
-      auto&& handler =
-        decayed_t::error_t::handle(std::forward<ErrorFunc>(error_func));
-      return std::invoke(std::move(handler), std::forward<decltype(e)>(e));
-    };
+    return all_same_way_t<ErrorFunc>{std::forward<ErrorFunc>(error_func)};
   };
 
   // get a new errorator by extending current one with new error