[Lldb-commits] [lldb] r305462 - Add llvm::Error assignment operator to Status class
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu Jun 15 04:23:27 PDT 2017
Author: labath
Date: Thu Jun 15 06:23:26 2017
New Revision: 305462
URL: http://llvm.org/viewvc/llvm-project?rev=305462&view=rev
Log:
Add llvm::Error assignment operator to Status class
This enables writing "status = std::move(some_llvm_error)".
Modified:
lldb/trunk/include/lldb/Utility/Status.h
lldb/trunk/source/Utility/Status.cpp
lldb/trunk/unittests/Utility/StatusTest.cpp
Modified: lldb/trunk/include/lldb/Utility/Status.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Status.h?rev=305462&r1=305461&r2=305462&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/Status.h (original)
+++ lldb/trunk/include/lldb/Utility/Status.h Thu Jun 15 06:23:26 2017
@@ -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;
//------------------------------------------------------------------
Modified: lldb/trunk/source/Utility/Status.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Status.cpp?rev=305462&r1=305461&r2=305462&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Status.cpp (original)
+++ lldb/trunk/source/Utility/Status.cpp Thu Jun 15 06:23:26 2017
@@ -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 {
Modified: lldb/trunk/unittests/Utility/StatusTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/StatusTest.cpp?rev=305462&r1=305461&r2=305462&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/StatusTest.cpp (original)
+++ lldb/trunk/unittests/Utility/StatusTest.cpp Thu Jun 15 06:23:26 2017
@@ -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) {
More information about the lldb-commits
mailing list