[Support] Make Error::isA<T>() works on success values.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263745 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Lang Hames 2016-03-17 20:35:00 +00:00
parent 367051414e
commit 3d86278890
2 changed files with 4 additions and 1 deletions

View File

@ -195,7 +195,7 @@ public:
/// Check whether one error is a subclass of another.
template <typename ErrT> bool isA() const {
return getPtr()->isA(ErrT::classID());
return getPtr() && getPtr()->isA(ErrT::classID());
}
private:

View File

@ -149,14 +149,17 @@ TEST(Error, CheckCustomErrors) {
{
Error E = make_error<CustomError>(1);
Error F = make_error<CustomSubError>(1, 2);
Error G = Error::success();
EXPECT_TRUE(E.isA<CustomError>());
EXPECT_FALSE(E.isA<CustomSubError>());
EXPECT_TRUE(F.isA<CustomError>());
EXPECT_TRUE(F.isA<CustomSubError>());
EXPECT_FALSE(G.isA<CustomError>());
consumeError(std::move(E));
consumeError(std::move(F));
consumeError(std::move(G));
}
// Check that we can handle a custom error.