Skip to content

Commit

Permalink
[Error] Make ECError only constructible via errorCodeToError.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lhames committed May 26, 2016
1 parent 2562aca commit 4040744
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/llvm/Support/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,9 +835,8 @@ template <class T> class Expected {
/// (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(); }
Expand All @@ -846,14 +845,16 @@ class ECError : public ErrorInfo<ECError> {
static char ID;

protected:
ECError() = default;
ECError(std::error_code EC) : EC(EC) {}
std::error_code EC;
};

/// Helper for converting an std::error_code to a Error.
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.
Expand Down

0 comments on commit 4040744

Please sign in to comment.