SemaExceptionSpec - silence static analyzer getAs<> null dereference warnings. NFCI.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Mon, 21 Oct 2019 18:28:31 +0000 (18:28 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Mon, 21 Oct 2019 18:28:31 +0000 (18:28 +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: 375440

clang/lib/Sema/SemaExceptionSpec.cpp

index b334ba5..c1abf09 100644 (file)
@@ -263,8 +263,7 @@ static bool hasImplicitExceptionSpec(FunctionDecl *Decl) {
   if (!Decl->getTypeSourceInfo())
     return isa<CXXDestructorDecl>(Decl);
 
-  const FunctionProtoType *Ty =
-    Decl->getTypeSourceInfo()->getType()->getAs<FunctionProtoType>();
+  auto *Ty = Decl->getTypeSourceInfo()->getType()->castAs<FunctionProtoType>();
   return !Ty->hasExceptionSpec();
 }
 
@@ -965,9 +964,9 @@ bool Sema::CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
                                   PDiag(diag::err_deep_exception_specs_differ),
                                   PDiag(diag::note_overridden_virtual_function),
                                   PDiag(diag::ext_override_exception_spec),
-                                  Old->getType()->getAs<FunctionProtoType>(),
+                                  Old->getType()->castAs<FunctionProtoType>(),
                                   Old->getLocation(),
-                                  New->getType()->getAs<FunctionProtoType>(),
+                                  New->getType()->castAs<FunctionProtoType>(),
                                   New->getLocation());
 }