aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Error.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-06-14 11:35:27 +0200
committerGitHub <noreply@github.com>2024-06-14 11:35:27 +0200
commit44df1167f88cabbb4cfde816f279337379ea30b3 (patch)
treeac5d601943f3c63519f6812e276da4aaff7de901 /llvm/lib/Support/Error.cpp
parent4bccd25467ce591869dad41c8b7c550093c20f1b (diff)
downloadllvm-44df1167f88cabbb4cfde816f279337379ea30b3.zip
llvm-44df1167f88cabbb4cfde816f279337379ea30b3.tar.gz
llvm-44df1167f88cabbb4cfde816f279337379ea30b3.tar.bz2
[Error] Add non-consuming toString (#95375)
There are some places that want to convert an Error to string, but still retain the original Error object, for example to emit a non-fatal warning. This currently isn't possible, because the entire Error infra is move-based. And what people end up doing in this case is to move the Error... twice. This patch introduces a toStringWithoutConsuming() function to accommodate this use case. This also requires some infrastructure that allows visiting Errors without consuming them.
Diffstat (limited to 'llvm/lib/Support/Error.cpp')
-rw-r--r--llvm/lib/Support/Error.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Support/Error.cpp b/llvm/lib/Support/Error.cpp
index 34ec31e..93481ca 100644
--- a/llvm/lib/Support/Error.cpp
+++ b/llvm/lib/Support/Error.cpp
@@ -82,6 +82,14 @@ std::string toString(Error E) {
return join(Errors.begin(), Errors.end(), "\n");
}
+std::string toStringWithoutConsuming(const Error &E) {
+ SmallVector<std::string, 2> Errors;
+ visitErrors(E, [&Errors](const ErrorInfoBase &EI) {
+ Errors.push_back(EI.message());
+ });
+ return join(Errors.begin(), Errors.end(), "\n");
+}
+
std::error_code ErrorList::convertToErrorCode() const {
return std::error_code(static_cast<int>(ErrorErrorCode::MultipleErrors),
getErrorErrorCat());