Skip to content

Commit a329cf6

Browse files
committed
[Support][Error] Unfriend FileError. It is not special.
FileError doesn't need direct access to Error's internals as it can access the payload via handleErrors. (ErrorList remains special: it is not possible to write a handler for it, due to the special auto-unpacking treatment that it receives from handleErrors.)
1 parent 9bdfee2 commit a329cf6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

llvm/include/llvm/Support/Error.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ class ErrorInfoBase {
155155
/// they're moved-assigned or constructed from Success values that have already
156156
/// been checked. This enforces checking through all levels of the call stack.
157157
class LLVM_NODISCARD Error {
158-
// Both ErrorList and FileError need to be able to yank ErrorInfoBase
159-
// pointers out of this class to add to the error list.
158+
// ErrorList needs to be able to yank ErrorInfoBase pointers out of Errors
159+
// to add to the error list. It can't rely on handleErrors for this, since
160+
// handleErrors does not support ErrorList handlers.
160161
friend class ErrorList;
161-
friend class FileError;
162162

163163
// handleErrors needs to be able to set the Checked flag.
164164
template <typename... HandlerTs>
@@ -1251,8 +1251,14 @@ class FileError final : public ErrorInfo<FileError> {
12511251
}
12521252

12531253
static Error build(const Twine &F, Optional<size_t> Line, Error E) {
1254+
std::unique_ptr<ErrorInfoBase> Payload;
1255+
handleAllErrors(std::move(E),
1256+
[&](std::unique_ptr<ErrorInfoBase> EIB) -> Error {
1257+
Payload = std::move(EIB);
1258+
return Error::success();
1259+
});
12541260
return Error(
1255-
std::unique_ptr<FileError>(new FileError(F, Line, E.takePayload())));
1261+
std::unique_ptr<FileError>(new FileError(F, Line, std::move(Payload))));
12561262
}
12571263

12581264
std::string FileName;

0 commit comments

Comments
 (0)