[Support] Make all Errors convertible to std::error_code.
This is a temporary crutch to enable code that currently uses std::error_code
to be incrementally moved over to Error. Requiring all Error instances be
convertible enables clients to call errorToErrorCode on any error (not just
ECErrors created by conversion *from* an error_code).
This patch also moves code for Error from ErrorHandling.cpp into a new
Error.cpp file.
llvm-svn: 264221
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index 788dcd3..1807547 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -9,6 +9,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/Errc.h"
+#include "llvm/Support/ErrorHandling.h"
#include "gtest/gtest.h"
#include <memory>
@@ -30,6 +31,10 @@
OS << "CustomError { " << getInfo() << "}";
}
+ std::error_code convertToErrorCode() const override {
+ llvm_unreachable("CustomError doesn't support ECError conversion");
+ }
+
protected:
// This error is subclassed below, but we can't use inheriting constructors
// yet, so we can't propagate the constructors through ErrorInfo. Instead
@@ -57,6 +62,10 @@
OS << "CustomSubError { " << getInfo() << ", " << getExtraInfo() << "}";
}
+ std::error_code convertToErrorCode() const override {
+ llvm_unreachable("CustomSubError doesn't support ECError conversion");
+ }
+
protected:
int ExtraInfo;
};