[llvm] a329cf6 - [Support][Error] Unfriend FileError. It is not special.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 20 15:08:52 PST 2019


Author: Lang Hames
Date: 2019-11-20T15:08:37-08:00
New Revision: a329cf69696f1d1103c569b4c4d68d212b204710

URL: https://github.com/llvm/llvm-project/commit/a329cf69696f1d1103c569b4c4d68d212b204710
DIFF: https://github.com/llvm/llvm-project/commit/a329cf69696f1d1103c569b4c4d68d212b204710.diff

LOG: [Support][Error] Unfriend FileError. It is not special.

FileError doesn't need direct access to Error's internals as it can access the
payload via handleErrors.

(ErrorList remains special: it is not possible to write a handler for it, due
to the special auto-unpacking treatment that it receives from handleErrors.)

Added: 
    

Modified: 
    llvm/include/llvm/Support/Error.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h
index 350877a219bf..75fca01b1270 100644
--- a/llvm/include/llvm/Support/Error.h
+++ b/llvm/include/llvm/Support/Error.h
@@ -155,10 +155,10 @@ class ErrorInfoBase {
 /// they're moved-assigned or constructed from Success values that have already
 /// been checked. This enforces checking through all levels of the call stack.
 class LLVM_NODISCARD Error {
-  // Both ErrorList and FileError need to be able to yank ErrorInfoBase
-  // pointers out of this class to add to the error list.
+  // ErrorList needs to be able to yank ErrorInfoBase pointers out of Errors
+  // to add to the error list. It can't rely on handleErrors for this, since
+  // handleErrors does not support ErrorList handlers.
   friend class ErrorList;
-  friend class FileError;
 
   // handleErrors needs to be able to set the Checked flag.
   template <typename... HandlerTs>
@@ -1251,8 +1251,14 @@ class FileError final : public ErrorInfo<FileError> {
   }
 
   static Error build(const Twine &F, Optional<size_t> Line, Error E) {
+    std::unique_ptr<ErrorInfoBase> Payload;
+    handleAllErrors(std::move(E),
+                    [&](std::unique_ptr<ErrorInfoBase> EIB) -> Error {
+                      Payload = std::move(EIB);
+                      return Error::success();
+                    });
     return Error(
-        std::unique_ptr<FileError>(new FileError(F, Line, E.takePayload())));
+        std::unique_ptr<FileError>(new FileError(F, Line, std::move(Payload))));
   }
 
   std::string FileName;


        


More information about the llvm-commits mailing list