[Support] Make Error::isA<T>() works on success values.
authorLang Hames <lhames@gmail.com>
Thu, 17 Mar 2016 20:35:00 +0000 (20:35 +0000)
committerLang Hames <lhames@gmail.com>
Thu, 17 Mar 2016 20:35:00 +0000 (20:35 +0000)
llvm-svn: 263745

llvm/include/llvm/Support/Error.h
llvm/unittests/Support/ErrorTest.cpp

index b0eaa44..33a3bc9 100644 (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:
index ed3d1c1..d5af2ca 100644 (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.