[clang-tools-extra] ed5d659 - [clang-tidy] NoexceptMoveConstructorCheck::check - use castAs<> instead of getAs<> to avoid dereference of nullptr

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


Author: Simon Pilgrim
Date: 2022-02-12T10:57:09Z
New Revision: ed5d659038362d6ccfebad3d9b7e10e73e681196

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

LOG: [clang-tidy] NoexceptMoveConstructorCheck::check - use castAs<> instead of getAs<> 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/performance/NoexceptMoveConstructorCheck.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp b/clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp
index f87f214945fa2..782498bd69e9a 100644
--- a/clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp
@@ -38,7 +38,7 @@ void NoexceptMoveConstructorCheck::check(
       return;
     }
 
-    const auto *ProtoType = Decl->getType()->getAs<FunctionProtoType>();
+    const auto *ProtoType = Decl->getType()->castAs<FunctionProtoType>();
 
     if (isUnresolvedExceptionSpec(ProtoType->getExceptionSpecType()))
       return;


        


More information about the cfe-commits mailing list