[PATCH] D49824: [Support] Introduce createStringError helper function

Lang Hames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 25 16:34:53 PDT 2018


lhames added inline comments.


================
Comment at: include/llvm/Support/Error.h:1125-1133
+/// Create formatted StringError object.
+template <typename... Ts>
+Error createStringError(char const *Fmt, const Ts &... Vals) {
+  std::string Buffer;
+  raw_string_ostream Stream(Buffer);
+  Stream << format(Fmt, Vals...);
+  return make_error<StringError>(Stream.str(), inconvertibleErrorCode());
----------------
For now I think this needs to take the std::error_code for the StringError as an argument too, rather than using inconvertibleErrorCode().

The reason for this is that using inconvertibleErrorCode breaks Error / std::error_code interoperability: any attempt to convert an Error value constructed with an inconvertibleErrorCode triggers an immediate abort. It is meant to be used explicitly, and only for code that explicitly documents that it does not support interoperability. It should not be default behavior.

Given the increasingly wide adoption of Error we could talk about changing this policy, but that is a discussion we should have on the dev list where it will reach a wide audience.


Repository:
  rL LLVM

https://reviews.llvm.org/D49824





More information about the llvm-commits mailing list