diff options
author | Lang Hames <lhames@gmail.com> | 2016-07-13 21:13:05 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-07-13 21:13:05 +0000 |
commit | c2773e97d248c396636464de9726c04efe47bf03 (patch) | |
tree | d06cf695118c691289eabb963bdd2613836388c2 /llvm/lib/Support/Error.cpp | |
parent | 02c15da062621032fbb9d72b73ee1996be9205ec (diff) | |
download | bcm5719-llvm-c2773e97d248c396636464de9726c04efe47bf03.tar.gz bcm5719-llvm-c2773e97d248c396636464de9726c04efe47bf03.zip |
[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).
llvm-svn: 275316
Diffstat (limited to 'llvm/lib/Support/Error.cpp')
-rw-r--r-- | llvm/lib/Support/Error.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Support/Error.cpp b/llvm/lib/Support/Error.cpp index df540d10bc5..6b22691eb1a 100644 --- a/llvm/lib/Support/Error.cpp +++ b/llvm/lib/Support/Error.cpp @@ -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); +} + } |