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

Christian Kandeler via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 29 07:13:05 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;
----------------
ckandeler wrote:

The fact that the code uses an unchecked cast implies a priori knowledge about the safety to do so, so static_cast seems to be the correct equivalent. Using dynamic_cast would likely incur unwanted overhead.
(I'm not too familiar with the clang-tidy code base: Is it possible/recommended to suggest competing fixes? If so, what happens to the respective code if --fix is used?)

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


More information about the cfe-commits mailing list