summaryrefslogtreecommitdiff
path: root/COFF/Error.h
diff options
context:
space:
mode:
Diffstat (limited to 'COFF/Error.h')
-rw-r--r--COFF/Error.h18
1 files changed, 14 insertions, 4 deletions
diff --git a/COFF/Error.h b/COFF/Error.h
index cb0a185f0917..c9f64c662580 100644
--- a/COFF/Error.h
+++ b/COFF/Error.h
@@ -11,15 +11,25 @@
#define LLD_COFF_ERROR_H
#include "lld/Core/LLVM.h"
+#include "llvm/Support/Error.h"
namespace lld {
namespace coff {
-LLVM_ATTRIBUTE_NORETURN void error(const Twine &Msg);
-void error(std::error_code EC, const Twine &Prefix);
+LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg);
+LLVM_ATTRIBUTE_NORETURN void fatal(std::error_code EC, const Twine &Prefix);
+LLVM_ATTRIBUTE_NORETURN void fatal(llvm::Error &Err, const Twine &Prefix);
-template <typename T> void error(const ErrorOr<T> &V, const Twine &Prefix) {
- error(V.getError(), Prefix);
+template <class T> T check(ErrorOr<T> &&V, const Twine &Prefix) {
+ if (auto EC = V.getError())
+ fatal(EC, Prefix);
+ return std::move(*V);
+}
+
+template <class T> T check(Expected<T> E, const Twine &Prefix) {
+ if (llvm::Error Err = E.takeError())
+ fatal(Err, Prefix);
+ return std::move(*E);
}
} // namespace coff