[llvm] [Support] Introduce formatv variant of createStringError (PR #80493)

Alex Langford via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 2 18:21:38 PST 2024


bulbazord wrote:

> I don't know what all your use cases are but for that specific example you can write `createStringError(..., "Something went wrong: " + Foo);` which uses the Twine version.

Yep, that's an option for this example. I was also thinking about string interpolation with other types (including some from LLDB directly). In LLDB we often construct `StringErrors` with multiple bits of information in them, not just strings. If we have a `std::string` or a `const char *` then this isn't a concern, but if we have a StringRef, we either need to do the `.str().c_str()` song and dance or build our message with `formatv` first. The former means potential (otherwise unneeded) small allocations, the second is a lot of code compared to a variation of `createStringError`.



> Thanks for the PR. This helps avoid the dangerous `llvm::format`.
> 
> I left a comment on https://discourse.llvm.org/t/llvm-format-is-dangerous/71994/16?u=maskray so that more folks are ware of this PR. This LGTM but it should wait a bit seeking more opinions.

Thanks for doing that, I wasn't aware of that thread. I'll wait at least a few days before landing this to give folks the time to look it over and discuss.

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


More information about the llvm-commits mailing list