[clang-tidy] getLambdaProperties - use cast<> instead of dyn_cast<> to avoid derefere...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Mon, 31 Jan 2022 17:23:03 +0000 (17:23 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Mon, 31 Jan 2022 17:25:16 +0000 (17:25 +0000)
The pointers are dereferenced immediately, so assert the cast is correct instead of returning nullptr

clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp

index 960eb7b..8b7373b 100644 (file)
@@ -548,11 +548,10 @@ getLambdaProperties(const MatchFinder::MatchResult &Result) {
   LambdaProperties LP;
 
   const auto *Bind = Result.Nodes.getNodeAs<CallExpr>("bind");
-  const auto *Decl = dyn_cast<FunctionDecl>(Bind->getCalleeDecl());
-  const auto *NS =
-      dyn_cast<NamespaceDecl>(Decl->getEnclosingNamespaceContext());
+  const auto *Decl = cast<FunctionDecl>(Bind->getCalleeDecl());
+  const auto *NS = cast<NamespaceDecl>(Decl->getEnclosingNamespaceContext());
   while (NS->isInlineNamespace())
-    NS = dyn_cast<NamespaceDecl>(NS->getDeclContext());
+    NS = cast<NamespaceDecl>(NS->getDeclContext());
   LP.BindNamespace = NS->getName();
 
   LP.Callable.Type = getCallableType(Result);