[clang-tools-extra] [clang-tidy] Provide fix-its for downcasts in google-readability-casting (PR #165411)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 28 19:45:21 PDT 2025


================
@@ -269,6 +269,12 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
       return;
     }
     break;
+  case CK_BaseToDerived:
+    if (!needsConstCast(SourceType, DestType)) {
+      ReplaceWithNamedCast("static_cast");
+      return;
+    }
+    break;
----------------
HerrCai0907 wrote:

Is it a best practice to use `static_cast` for base to derived always?
I think under RTTI, we should use `dynamic_cast` and under non-RTTI, `static_cast` could be used also.

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


More information about the cfe-commits mailing list