mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-24 06:10:12 +00:00
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:
parent
054243f75a
commit
3adc40876e
@ -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;
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user