mirror of
https://github.com/RPCS3/llvm.git
synced 2026-07-18 21:24:32 -04:00
[Object] Change Archive::child_iterator for better interop with Error/Expected.
See http://reviews.llvm.org/D22079 Changes the Archive::child_begin and Archive::children to require a reference to an Error. If iterator increment fails (because the archive header is damaged) the iterator will be set to 'end()', and the error stored in the given Error&. The Error value should be checked by the user immediately after the loop. E.g.: Error Err; for (auto &C : A->children(Err)) { // Do something with archive child C. } // Check the error immediately after the loop. if (Err) return Err; Failure to check the Error will result in an abort() when the Error goes out of scope (as guaranteed by the Error class). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275316 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -64,6 +64,7 @@ void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
std::error_code ErrorList::convertToErrorCode() const {
|
||||
return std::error_code(static_cast<int>(ErrorErrorCode::MultipleErrors),
|
||||
*ErrorErrorCat);
|
||||
@@ -99,4 +100,14 @@ std::error_code StringError::convertToErrorCode() const {
|
||||
return EC;
|
||||
}
|
||||
|
||||
void report_fatal_error(Error Err, bool GenCrashDiag) {
|
||||
assert(Err && "report_fatal_error called with success value");
|
||||
std::string ErrMsg;
|
||||
{
|
||||
raw_string_ostream ErrStream(ErrMsg);
|
||||
logAllUnhandledErrors(std::move(Err), ErrStream, "");
|
||||
}
|
||||
report_fatal_error(ErrMsg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user