[llvm] r270916 - [Error] Make ECError only constructible via errorCodeToError.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Thu May 26 14:15:58 PDT 2016


Author: lhames
Date: Thu May 26 16:15:58 2016
New Revision: 270916

URL: http://llvm.org/viewvc/llvm-project?rev=270916&view=rev
Log:
[Error] Make ECError only constructible via errorCodeToError.

This enforces idiomatic usage of ECError removing the option to construct them
using make_error.


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

Modified: llvm/trunk/include/llvm/Support/Error.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Error.h?rev=270916&r1=270915&r2=270916&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Error.h (original)
+++ llvm/trunk/include/llvm/Support/Error.h Thu May 26 16:15:58 2016
@@ -835,9 +835,8 @@ private:
 /// (or Expected) and you want to call code that still returns
 /// std::error_codes.
 class ECError : public ErrorInfo<ECError> {
+  friend Error errorCodeToError(std::error_code);
 public:
-  ECError() = default;
-  ECError(std::error_code EC) : EC(EC) {}
   void setErrorCode(std::error_code EC) { this->EC = EC; }
   std::error_code convertToErrorCode() const override { return EC; }
   void log(raw_ostream &OS) const override { OS << EC.message(); }
@@ -846,6 +845,8 @@ public:
   static char ID;
 
 protected:
+  ECError() = default;
+  ECError(std::error_code EC) : EC(EC) {}
   std::error_code EC;
 };
 
@@ -853,7 +854,7 @@ protected:
 inline Error errorCodeToError(std::error_code EC) {
   if (!EC)
     return Error::success();
-  return make_error<ECError>(EC);
+  return Error(llvm::make_unique<ECError>(ECError(EC)));
 }
 
 /// Helper for converting an ECError to a std::error_code.




More information about the llvm-commits mailing list