aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/ErrorTest.cpp
diff options
context:
space:
mode:
authorMehdi Amini <mehdi.amini@apple.com>2016-11-11 04:29:25 +0000
committerMehdi Amini <mehdi.amini@apple.com>2016-11-11 04:29:25 +0000
commitc1edf566b9ba18806c9a69e77db1cc8e57a14c8d (patch)
treeea1b174a6e594d2b6929f9e4845cc2ba3d9d6f93 /llvm/unittests/Support/ErrorTest.cpp
parent41af43092ccc8030bb49cea324d85eecd5ae68a8 (diff)
downloadllvm-c1edf566b9ba18806c9a69e77db1cc8e57a14c8d.zip
llvm-c1edf566b9ba18806c9a69e77db1cc8e57a14c8d.tar.gz
llvm-c1edf566b9ba18806c9a69e77db1cc8e57a14c8d.tar.bz2
Prevent at compile time converting from Error::success() to Expected<T>
This would trigger an assertion at runtime otherwise. Differential Revision: https://reviews.llvm.org/D26482 llvm-svn: 286562
Diffstat (limited to 'llvm/unittests/Support/ErrorTest.cpp')
-rw-r--r--llvm/unittests/Support/ErrorTest.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index 7468a85..1fe9017 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -97,14 +97,15 @@ static void handleCustomErrorUPVoid(std::unique_ptr<CustomError> CE) {}
// Test that success values implicitly convert to false, and don't cause crashes
// once they've been implicitly converted.
TEST(Error, CheckedSuccess) {
- Error E;
+ Error E = Error::success();
EXPECT_FALSE(E) << "Unexpected error while testing Error 'Success'";
}
// Test that unchecked succes values cause an abort.
#ifndef NDEBUG
TEST(Error, UncheckedSuccess) {
- EXPECT_DEATH({ Error E; }, "Program aborted due to an unhandled Error:")
+ EXPECT_DEATH({ Error E = Error::success(); },
+ "Program aborted due to an unhandled Error:")
<< "Unchecked Error Succes value did not cause abort()";
}
#endif
@@ -121,7 +122,7 @@ void errAsOutParamHelper(Error &Err) {
// Test that ErrorAsOutParameter sets the checked flag on construction.
TEST(Error, ErrorAsOutParameterChecked) {
- Error E;
+ Error E = Error::success();
errAsOutParamHelper(E);
(void)!!E;
}
@@ -129,7 +130,7 @@ TEST(Error, ErrorAsOutParameterChecked) {
// Test that ErrorAsOutParameter clears the checked flag on destruction.
#ifndef NDEBUG
TEST(Error, ErrorAsOutParameterUnchecked) {
- EXPECT_DEATH({ Error E; errAsOutParamHelper(E); },
+ EXPECT_DEATH({ Error E = Error::success(); errAsOutParamHelper(E); },
"Program aborted due to an unhandled Error:")
<< "ErrorAsOutParameter did not clear the checked flag on destruction.";
}
@@ -197,31 +198,31 @@ TEST(Error, HandlerTypeDeduction) {
handleAllErrors(
make_error<CustomError>(42),
- [](const CustomError &CE) mutable { return Error::success(); });
+ [](const CustomError &CE) mutable -> Error { return Error::success(); });
handleAllErrors(make_error<CustomError>(42),
[](const CustomError &CE) mutable {});
handleAllErrors(make_error<CustomError>(42),
- [](CustomError &CE) { return Error::success(); });
+ [](CustomError &CE) -> Error { return Error::success(); });
handleAllErrors(make_error<CustomError>(42), [](CustomError &CE) {});
handleAllErrors(make_error<CustomError>(42),
- [](CustomError &CE) mutable { return Error::success(); });
+ [](CustomError &CE) mutable -> Error { return Error::success(); });
handleAllErrors(make_error<CustomError>(42), [](CustomError &CE) mutable {});
handleAllErrors(
make_error<CustomError>(42),
- [](std::unique_ptr<CustomError> CE) { return Error::success(); });
+ [](std::unique_ptr<CustomError> CE) -> Error { return Error::success(); });
handleAllErrors(make_error<CustomError>(42),
[](std::unique_ptr<CustomError> CE) {});
handleAllErrors(
make_error<CustomError>(42),
- [](std::unique_ptr<CustomError> CE) mutable { return Error::success(); });
+ [](std::unique_ptr<CustomError> CE) mutable -> Error { return Error::success(); });
handleAllErrors(make_error<CustomError>(42),
[](std::unique_ptr<CustomError> CE) mutable {});
@@ -365,7 +366,7 @@ TEST(Error, CheckJoinErrors) {
// Test that we can consume success values.
TEST(Error, ConsumeSuccess) {
- Error E;
+ Error E = Error::success();
consumeError(std::move(E));
}