From 40407440a47a17479dee644a6cadd64c082bc5b1 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270916 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Error.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/llvm/Support/Error.h b/include/llvm/Support/Error.h index 2452ffa468f2..a8152e871dc8 100644 --- a/include/llvm/Support/Error.h +++ b/include/llvm/Support/Error.h @@ -835,9 +835,8 @@ template class Expected { /// (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 @@ class ECError : public ErrorInfo { static char ID; protected: + ECError() = default; + ECError(std::error_code EC) : EC(EC) {} std::error_code EC; }; @@ -853,7 +854,7 @@ class ECError : public ErrorInfo { 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.