DeclCXX/ExprCXX - silence static analyzer getAs<> null dereference warnings. NFCI.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Mon, 30 Sep 2019 11:04:12 +0000 (11:04 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Mon, 30 Sep 2019 11:04:12 +0000 (11:04 +0000)
The static analyzer is warning about potential null dereferences, but in these cases we should be able to use castAs<> directly and if not assert will fire for us.

llvm-svn: 373198

clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/ExprCXX.h

index 7ec391f..0b835ec 100644 (file)
@@ -2236,7 +2236,7 @@ public:
                                     const CXXRecordDecl *Decl);
 
   Qualifiers getMethodQualifiers() const {
-    return getType()->getAs<FunctionProtoType>()->getMethodQuals();
+    return getType()->castAs<FunctionProtoType>()->getMethodQuals();
   }
 
   /// Retrieve the ref-qualifier associated with this method.
@@ -2251,7 +2251,7 @@ public:
   /// };
   /// @endcode
   RefQualifierKind getRefQualifier() const {
-    return getType()->getAs<FunctionProtoType>()->getRefQualifier();
+    return getType()->castAs<FunctionProtoType>()->getRefQualifier();
   }
 
   bool hasInlineBody() const;
@@ -2905,7 +2905,7 @@ public:
 
   /// Returns the type that this conversion function is converting to.
   QualType getConversionType() const {
-    return getType()->getAs<FunctionType>()->getReturnType();
+    return getType()->castAs<FunctionType>()->getReturnType();
   }
 
   /// Determine whether this conversion function is a conversion from
index e554968..bc7d7c0 100644 (file)
@@ -2096,8 +2096,7 @@ public:
                                  bool IsParenTypeId);
 
   QualType getAllocatedType() const {
-    assert(getType()->isPointerType());
-    return getType()->getAs<PointerType>()->getPointeeType();
+    return getType()->castAs<PointerType>()->getPointeeType();
   }
 
   TypeSourceInfo *getAllocatedTypeSourceInfo() const {