[clang-tools-extra] [clang-tidy] detect redundant uses of LLVM's cast, dyn_cast (PR #189274)

via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 29 11:37:48 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- clang-tools-extra/clang-tidy/llvm/RedundantCastingCheck.cpp clang-tools-extra/clang-tidy/llvm/RedundantCastingCheck.h clang-tools-extra/test/clang-tidy/checkers/llvm/redundant-casting.cpp clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang-tools-extra/clang-tidy/llvm/RedundantCastingCheck.cpp b/clang-tools-extra/clang-tidy/llvm/RedundantCastingCheck.cpp
index a29701cc0..dfba87035 100644
--- a/clang-tools-extra/clang-tidy/llvm/RedundantCastingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/RedundantCastingCheck.cpp
@@ -49,12 +49,10 @@ void RedundantCastingCheck::registerMatchers(MatchFinder *Finder) {
                          unresolvedLookupExpr(hasAnyUnresolvedName(CalleeName))
                              .bind("callee")))));
       };
-  Finder->addMatcher(
-      callExpr(
-          AnyCalleeName(FunctionNames),
-          hasAncestor(functionDecl().bind("context")))
-          .bind("call"),
-      this);
+  Finder->addMatcher(callExpr(AnyCalleeName(FunctionNames),
+                              hasAncestor(functionDecl().bind("context")))
+                         .bind("call"),
+                     this);
   Finder->addMatcher(
       callExpr(AnyCalleeNameInUninstantiatedTemplate(FunctionNames))
           .bind("call"),
@@ -106,7 +104,8 @@ void RedundantCastingCheck::check(const MatchFinder::MatchResult &Result) {
       stripPointerOrReference(Arg->getType())->getCanonicalTypeUnqualified();
   const auto *FromDecl = FromTy->getAsCXXRecordDecl();
   const auto *RetDecl = RetTy->getAsCXXRecordDecl();
-  const bool IsDerived = FromDecl && RetDecl && FromDecl->isDerivedFrom(RetDecl);
+  const bool IsDerived =
+      FromDecl && RetDecl && FromDecl->isDerivedFrom(RetDecl);
   if (FromTy != RetTy && !IsDerived)
     return;
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/189274


More information about the cfe-commits mailing list