Bug Bug 1355739 - Part1: Pass lvalue callable object into MakeScopeExit should be allowd. draft
authorJames Cheng <jacheng@mozilla.com>
Wed, 12 Apr 2017 16:32:57 +0800
changeset 561110 d2d4217fe7f99a54b1652dcf50a33b648efd65e6
parent 560921 f40e24f40b4c4556944c762d4764eace261297f5
child 561111 598b593f548a2eac7a6aaa5b6c200f9209fd7c60
child 561237 647c14f3d183dab9c1d3aef273d3b96b2f7cfb38
push id53640
push userbmo:jacheng@mozilla.com
push dateWed, 12 Apr 2017 08:33:35 +0000
bugs1355739
milestone55.0a1
Bug Bug 1355739 - Part1: Pass lvalue callable object into MakeScopeExit should be allowd. MozReview-Commit-ID: AuB5MCXs0Fu
mfbt/ScopeExit.h
--- a/mfbt/ScopeExit.h
+++ b/mfbt/ScopeExit.h
@@ -119,17 +119,20 @@ public:
 
 private:
   explicit ScopeExit(const ScopeExit&) = delete;
   ScopeExit& operator=(const ScopeExit&) = delete;
   ScopeExit& operator=(ScopeExit&&) = delete;
 };
 
 template <typename ExitFunction>
-ScopeExit<ExitFunction>
+ScopeExit<typename RemoveConst<typename RemoveReference<ExitFunction>::Type>::Type>
 MakeScopeExit(ExitFunction&& exitFunction)
 {
-  return ScopeExit<ExitFunction>(mozilla::Move(exitFunction));
+  using RemoveCRType =
+    typename RemoveConst<typename RemoveReference<ExitFunction>::Type>::Type;
+  RemoveCRType exitFunc = exitFunction;
+  return ScopeExit<RemoveCRType>(mozilla::Move(exitFunc));
 }
 
 } /* namespace mozilla */
 
 #endif /* mozilla_ScopeExit_h */