[Lldb-commits] [lldb] [lldb] Change the implementation of Status to store an llvm::Error (NFC) (PR #106774)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 11 01:58:19 PDT 2024


================
@@ -181,29 +226,68 @@ const char *Status::AsCString(const char *default_error_str) const {
 
 // Clear the error and any cached error string that it might contain.
 void Status::Clear() {
-  m_code = 0;
-  m_type = eErrorTypeInvalid;
-  m_string.clear();
+  if (m_error)
+    LLDB_LOG_ERRORV(GetLog(LLDBLog::API), std::move(m_error),
+                    "dropping error {0}");
+  m_error = llvm::Error::success();
+  llvm::consumeError(std::move(m_error));
----------------
labath wrote:

Is there some invariant that holds (or that we could make hold) for the state of the checked flag in m_error? E.g., that it is always clear (until we reach the destructor), or that it is (should be) set immediately upon construction.

I'm asking this because I think that the flag is almost always clear, except that it is set in this function. But if you're doing that just so you can assign the error in operator=, then you could just set the flag there, and always maintain the invariant.

https://github.com/llvm/llvm-project/pull/106774


More information about the lldb-commits mailing list