[clang-tools-extra] 9acba52 - [clang-tidy] FunctionASTVisitor::TraverseStmt - 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 03:04:51 PST 2022


Author: Simon Pilgrim
Date: 2022-02-12T11:04:20Z
New Revision: 9acba5206a91d735bc56ba41f18eabfc81db0513

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

LOG: [clang-tidy] FunctionASTVisitor::TraverseStmt - 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/readability/FunctionCognitiveComplexityCheck.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
index c27733c040833..40542cca54a44 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -444,8 +444,7 @@ class FunctionASTVisitor final
       // A little beautification.
       // For conditional operator "cond ? true : false" point at the "?"
       // symbol.
-      ConditionalOperator *COp = dyn_cast<ConditionalOperator>(Node);
-      Location = COp->getQuestionLoc();
+      Location = cast<ConditionalOperator>(Node)->getQuestionLoc();
     }
 
     // If we have found any reasons, let's account it.


        


More information about the cfe-commits mailing list