[clang-tools-extra] r323443 - [clangd] Replace homegrown make_scope_exit with one from ADT

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 25 09:01:39 PST 2018


Author: sammccall
Date: Thu Jan 25 09:01:39 2018
New Revision: 323443

URL: http://llvm.org/viewvc/llvm-project?rev=323443&view=rev
Log:
[clangd] Replace homegrown make_scope_exit with one from ADT

Modified:
    clang-tools-extra/trunk/clangd/ClangdServer.cpp
    clang-tools-extra/trunk/clangd/Function.h

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=323443&r1=323442&r2=323443&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Thu Jan 25 09:01:39 2018
@@ -19,6 +19,7 @@
 #include "clang/Tooling/Refactoring/RefactoringResultConsumer.h"
 #include "clang/Tooling/Refactoring/Rename/RenamingAction.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatProviders.h"
@@ -576,7 +577,8 @@ std::future<Context> ClangdServer::sched
                 const Context &)>
                 DeferredRebuild,
             std::promise<Context> DonePromise, Context Ctx) -> void {
-    auto Guard = onScopeExit([&]() { DonePromise.set_value(std::move(Ctx)); });
+    auto Guard =
+        llvm::make_scope_exit([&]() { DonePromise.set_value(std::move(Ctx)); });
 
     auto CurrentVersion = DraftMgr.getVersion(FileStr);
     if (CurrentVersion != Version)

Modified: clang-tools-extra/trunk/clangd/Function.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Function.h?rev=323443&r1=323442&r2=323443&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Function.h (original)
+++ clang-tools-extra/trunk/clangd/Function.h Thu Jan 25 09:01:39 2018
@@ -137,40 +137,6 @@ ForwardBinder<Func, Args...> BindWithFor
       std::make_tuple(std::forward<Func>(F), std::forward<Args>(As)...));
 }
 
-namespace detail {
-/// Runs provided callback in destructor. Use onScopeExit helper function to
-/// create this object.
-template <class Func> struct ScopeExitGuard {
-  static_assert(std::is_same<typename std::decay<Func>::type, Func>::value,
-                "Func must be decayed");
-
-  ScopeExitGuard(Func F) : F(std::move(F)) {}
-  ~ScopeExitGuard() {
-    if (!F)
-      return;
-    (*F)();
-  }
-
-  // Move-only.
-  ScopeExitGuard(const ScopeExitGuard &) = delete;
-  ScopeExitGuard &operator=(const ScopeExitGuard &) = delete;
-
-  ScopeExitGuard(ScopeExitGuard &&Other) = default;
-  ScopeExitGuard &operator=(ScopeExitGuard &&Other) = default;
-
-private:
-  llvm::Optional<Func> F;
-};
-} // namespace detail
-
-/// Creates a RAII object that will run \p F in its destructor.
-template <class Func>
-auto onScopeExit(Func &&F)
-    -> detail::ScopeExitGuard<typename std::decay<Func>::type> {
-  return detail::ScopeExitGuard<typename std::decay<Func>::type>(
-      std::forward<Func>(F));
-}
-
 } // namespace clangd
 } // namespace clang
 




More information about the cfe-commits mailing list