Cast NULL when requested.
authorVikram S. Adve <vadve@cs.uiuc.edu>
Sun, 14 Oct 2001 23:21:06 +0000 (23:21 +0000)
committerVikram S. Adve <vadve@cs.uiuc.edu>
Sun, 14 Oct 2001 23:21:06 +0000 (23:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@803 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Value.h

index 8245f8fb35042c05ce011cf3508fc23868d9e27f..ea17c3ef2ec34f74fcc744377436627aadfe48ee 100644 (file)
@@ -193,14 +193,15 @@ inline bool isa(Y Val) { return X::classof(Val); }
 
 // cast<X> - Return the argument parameter cast to the specified type.  This
 // casting operator asserts that the type is correct, so it does not return null
-// on failure.  Used Like this:
+// on failure.  But it will correctly return NULL when the input is NULL.
+// Used Like this:
 //
 //  cast<      Instruction>(myVal)->getParent()
 //  cast<const Instruction>(myVal)->getParent()
 //
 template <class X, class Y>
 inline X *cast(Y Val) {
-  assert(isa<X>(Val) && "Invalid cast argument type!");
+  assert((Val == 0 || isa<X>(Val)) && "Invalid cast argument type!");
   return (X*)(real_type<Y>::Type)Val;
 }