[Lldb-commits] [lldb] [lldb] Turn lldb_private::Status into a value type. (PR #106163)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 27 03:09:54 PDT 2024


================
@@ -51,13 +51,13 @@ Status::Status(std::error_code EC)
                                                       : eErrorTypeGeneric),
       m_string(EC.message()) {}
 
-Status::Status(const char *format, ...) : m_string() {
-  va_list args;
-  va_start(args, format);
-  SetErrorToGenericError();
-  SetErrorStringWithVarArg(format, args);
-  va_end(args);
-}
+Status::Status(std::string &&err_str)
----------------
Michael137 wrote:

Why `std::string&&`? Looks like in a lot of the cases you're going to have to do a c-str -> std::string conversion anyway? For the `FromErrorStringWithFormat` where you construct `Status` with an l-value string, you're actually silently copying (because this `std::string&&` overload isn't picked, instead it picks the `llvm::StringRef` constructor, and copies the string).

All this might just be easier to reason about if you make it a by-value argument, for all cases. And the double-move (for std::move construction+std::move from the argument is probably not worth optimizing away by-hand?).

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


More information about the lldb-commits mailing list