[PATCH] D39990: Use TempFile in the implementation of LockFileManager

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 17 11:40:56 PST 2017


rnk accepted this revision.
rnk added a comment.

lgtm, let's give it a go.



================
Comment at: lib/Support/LockFileManager.cpp:175
+  // Make sure we discard the temporary file on exit.
+  RAIICleanup RemoveTempFile([&]() {
+    if (Error E = UniqueLockFile->discard())
----------------
This is total bikeshedding, but I like to write these RAII helpers inline, like:
  struct TempFileRemover {
    TempFile &TF;
    LockFileManager &LFM;
    bool Cancelled = false;
    TempFileRemover(TempFile &TF, LockFileManager &LFM) : TF(TF), LFM(LFM) {}
    ~TempFileRemover() {
      if (Cancelled)
        return;
      if (Error E = TF.discard())
        LFM.setError(errorToErrorCode(std::move(E)));
  } RemoveTempFile(*TempFile, *this);

It saves a std::function, but you have to write out the capture members and a constructor to initialize them. Maybe this is just what happens when your brain has been damaged from working on a C++ compiler too long.


https://reviews.llvm.org/D39990





More information about the llvm-commits mailing list