Simplify ErrorOr.

ErrorOr had quiet a bit of complexity and indirection to be able to hold a user
type with the error.

That feature is not used anymore. This patch removes it, it will live in svn
history if we ever need it again.

If we do need it again, IMHO there is one thing that should be done
differently: Holding extra info in the error is not a property a function also
returning a value or not. The ability to hold extra info should be in the error
type and ErrorOr templated over it so that we don't need the funny looking
ErrorOr<void>.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194030 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2013-11-05 00:28:01 +00:00
parent c88eb08d02
commit f94b3480fc
2 changed files with 5 additions and 252 deletions

View File

@@ -45,9 +45,6 @@ TEST(ErrorOr, Types) {
*a = 42;
EXPECT_EQ(42, x);
EXPECT_FALSE(ErrorOr<void>(errc::broken_pipe));
EXPECT_TRUE(ErrorOr<void>(errc::success));
#if LLVM_HAS_CXX11_STDLIB
// Move only types.
EXPECT_EQ(3, **t3());
@@ -67,38 +64,3 @@ TEST(ErrorOr, Covariant) {
#endif
}
} // end anon namespace
struct InvalidArgError {
InvalidArgError() {}
InvalidArgError(std::string S) : ArgName(S) {}
std::string ArgName;
};
namespace llvm {
template<>
struct ErrorOrUserDataTraits<InvalidArgError> : true_type {
static error_code error() {
return make_error_code(errc::invalid_argument);
}
};
} // end namespace llvm
ErrorOr<int> t4() {
return InvalidArgError("adena");
}
ErrorOr<void> t5() {
return InvalidArgError("pie");
}
namespace {
TEST(ErrorOr, UserErrorData) {
ErrorOr<int> a = t4();
EXPECT_EQ(errc::invalid_argument, a);
EXPECT_EQ("adena", t4().getError<InvalidArgError>().ArgName);
ErrorOr<void> b = t5();
EXPECT_EQ(errc::invalid_argument, b);
EXPECT_EQ("pie", b.getError<InvalidArgError>().ArgName);
}
} // end anon namespace