[clang-tools-extra] 99acc0d - [clang-tidy] UseNoexceptCheck::check - use cast<> instead of dyn_cast<> to avoid dereference of nullptr

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 12 02:56:38 PST 2022


Author: Simon Pilgrim
Date: 2022-02-12T10:51:48Z
New Revision: 99acc0dc6434373dc391ac4c89f6ae6b72ec7208

URL: https://github.com/llvm/llvm-project/commit/99acc0dc6434373dc391ac4c89f6ae6b72ec7208
DIFF: https://github.com/llvm/llvm-project/commit/99acc0dc6434373dc391ac4c89f6ae6b72ec7208.diff

LOG: [clang-tidy] UseNoexceptCheck::check - use cast<> instead of dyn_cast<> to avoid dereference of nullptr

The pointer is referenced immediately, so assert the cast is correct instead of returning nullptr

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
index c4e7f12e74acb..0043eb0dab9a4 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
@@ -65,7 +65,7 @@ void UseNoexceptCheck::check(const MatchFinder::MatchResult &Result) {
   } else if (const auto *ParmDecl =
                  Result.Nodes.getNodeAs<ParmVarDecl>("parmVarDecl")) {
     FnTy = ParmDecl->getType()
-               ->getAs<Type>()
+               ->castAs<Type>()
                ->getPointeeType()
                ->getAs<FunctionProtoType>();
 


        


More information about the cfe-commits mailing list