Add llvm::Error assignment operator to Status class

This enables writing "status = std::move(some_llvm_error)".

llvm-svn: 305462
This commit is contained in:
Pavel Labath 2017-06-15 11:23:26 +00:00
parent 054243f75a
commit 3adc40876e
3 changed files with 15 additions and 6 deletions

View File

@ -104,7 +104,8 @@ public:
~Status();
// llvm::Error support
explicit Status(llvm::Error error);
explicit Status(llvm::Error error) { *this = std::move(error); }
const Status &operator=(llvm::Error error);
llvm::Error ToError() const;
//------------------------------------------------------------------

View File

@ -56,10 +56,11 @@ Status::Status(const char *format, ...)
va_end(args);
}
Status::Status(llvm::Error error)
: m_code(0), m_type(ErrorType::eErrorTypeGeneric) {
if (!error)
return;
const Status &Status::operator=(llvm::Error error) {
if (!error) {
Clear();
return *this;
}
// if the error happens to be a errno error, preserve the error code
error = llvm::handleErrors(
@ -74,8 +75,12 @@ Status::Status(llvm::Error error)
});
// Otherwise, just preserve the message
if (error)
if (error) {
SetErrorToGenericError();
SetErrorString(llvm::toString(std::move(error)));
}
return *this;
}
llvm::Error Status::ToError() const {

View File

@ -33,6 +33,9 @@ TEST(StatusTest, ErrorConstructor) {
EXPECT_TRUE(foo.Fail());
EXPECT_EQ(eErrorTypeGeneric, foo.GetType());
EXPECT_STREQ("foo", foo.AsCString());
foo = llvm::Error::success();
EXPECT_TRUE(foo.Success());
}
TEST(StatusTest, ErrorConversion) {