[all-commits] [llvm/llvm-project] 4bb0ca: [Support] Introduce formatv variant of createStrin...
Alex Langford via All-commits
all-commits at lists.llvm.org
Fri Feb 16 16:26:25 PST 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 4bb0ca655bb65aae0a1d251ba5053aadff678101
https://github.com/llvm/llvm-project/commit/4bb0ca655bb65aae0a1d251ba5053aadff678101
Author: Alex Langford <alangford at apple.com>
Date: 2024-02-16 (Fri, 16 Feb 2024)
Changed paths:
M llvm/include/llvm/Support/Error.h
M llvm/unittests/Support/ErrorTest.cpp
Log Message:
-----------
[Support] Introduce formatv variant of createStringError (#80493)
Many times I have found myself wanting to create a StringError with the
ability to interpolate a StringRef into the error string. This can be
achieved with:
StringRef Foo("...");
auto Err = createStringError(..., "Something went wrong: %s",
Foo.str().c_str());
However, this requires us to construct a temporary std::string (which
may perform a memory allocation if large enough).
I propose a new variant of `createStringError` called
`createStringErrorV` which uses `formatv` under the hood. This allows
the above example to become:
StringRef Foo("...");
auto Err = createStringErrorV(..., "Something went wrong: {0}", Foo);
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list