[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
This commit is contained in:
Lang Hames 2016-05-26 21:15:58 +00:00
parent 2fa1c61618
commit 3a869dc481
1 changed files with 4 additions and 3 deletions

View File

@ -835,9 +835,8 @@ private:
/// (or Expected) and you want to call code that still returns /// (or Expected) and you want to call code that still returns
/// std::error_codes. /// std::error_codes.
class ECError : public ErrorInfo<ECError> { class ECError : public ErrorInfo<ECError> {
friend Error errorCodeToError(std::error_code);
public: public:
ECError() = default;
ECError(std::error_code EC) : EC(EC) {}
void setErrorCode(std::error_code EC) { this->EC = EC; } void setErrorCode(std::error_code EC) { this->EC = EC; }
std::error_code convertToErrorCode() const override { return EC; } std::error_code convertToErrorCode() const override { return EC; }
void log(raw_ostream &OS) const override { OS << EC.message(); } void log(raw_ostream &OS) const override { OS << EC.message(); }
@ -846,6 +845,8 @@ public:
static char ID; static char ID;
protected: protected:
ECError() = default;
ECError(std::error_code EC) : EC(EC) {}
std::error_code EC; std::error_code EC;
}; };
@ -853,7 +854,7 @@ protected:
inline Error errorCodeToError(std::error_code EC) { inline Error errorCodeToError(std::error_code EC) {
if (!EC) if (!EC)
return Error::success(); 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. /// Helper for converting an ECError to a std::error_code.