From 3a869dc4812c45f0ce9dd381ebe90f77e5640ede Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 26 May 2016 21:15:58 +0000 Subject: [PATCH] [Error] Make ECError only constructible via errorCodeToError. This enforces idiomatic usage of ECError removing the option to construct them using make_error. llvm-svn: 270916 --- llvm/include/llvm/Support/Error.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h index 2452ffa468f2..a8152e871dc8 100644 --- a/llvm/include/llvm/Support/Error.h +++ b/llvm/include/llvm/Support/Error.h @@ -835,9 +835,8 @@ private: /// (or Expected) and you want to call code that still returns /// std::error_codes. class ECError : public ErrorInfo { + 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(EC); + return Error(llvm::make_unique(ECError(EC))); } /// Helper for converting an ECError to a std::error_code.