diff options
author | Nikita Popov <npopov@redhat.com> | 2024-06-14 11:35:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-14 11:35:27 +0200 |
commit | 44df1167f88cabbb4cfde816f279337379ea30b3 (patch) | |
tree | ac5d601943f3c63519f6812e276da4aaff7de901 /llvm/unittests/Support/ErrorTest.cpp | |
parent | 4bccd25467ce591869dad41c8b7c550093c20f1b (diff) | |
download | llvm-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/unittests/Support/ErrorTest.cpp')
-rw-r--r-- | llvm/unittests/Support/ErrorTest.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp index 5d866a6..bd098a4 100644 --- a/llvm/unittests/Support/ErrorTest.cpp +++ b/llvm/unittests/Support/ErrorTest.cpp @@ -740,15 +740,25 @@ TEST(Error, ErrorCodeConversions) { TEST(Error, ErrorMessage) { EXPECT_EQ(toString(Error::success()), ""); + Error E0 = Error::success(); + EXPECT_EQ(toStringWithoutConsuming(E0), ""); + EXPECT_EQ(toString(std::move(E0)), ""); + Error E1 = make_error<CustomError>(0); + EXPECT_EQ(toStringWithoutConsuming(E1), "CustomError {0}"); EXPECT_EQ(toString(std::move(E1)), "CustomError {0}"); Error E2 = make_error<CustomError>(0); + visitErrors(E2, [](const ErrorInfoBase &EI) { + EXPECT_EQ(EI.message(), "CustomError {0}"); + }); handleAllErrors(std::move(E2), [](const CustomError &CE) { EXPECT_EQ(CE.message(), "CustomError {0}"); }); Error E3 = joinErrors(make_error<CustomError>(0), make_error<CustomError>(1)); + EXPECT_EQ(toStringWithoutConsuming(E3), "CustomError {0}\n" + "CustomError {1}"); EXPECT_EQ(toString(std::move(E3)), "CustomError {0}\n" "CustomError {1}"); } |