[clang] [Clang] Diagnose down casting static_cast (PR #117914)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 27 11:28:53 PST 2024


================
@@ -1759,6 +1759,16 @@ TryStaticDowncast(Sema &Self, CanQualType SrcType, CanQualType DestType,
 
   Self.BuildBasePathArray(Paths, BasePath);
   Kind = CK_BaseToDerived;
+
+  if (!CStyle && Self.LangOpts.CPlusPlus && SrcType->getAsCXXRecordDecl()->isPolymorphic()) {
+    auto D = Self.Diag(OpRange.getBegin(), diag::warn_static_downcast)
+        << SrcType << DestType
+        << OpRange
+        << Self.LangOpts.RTTI;
+    if(Self.LangOpts.RTTI)
----------------
AaronBallman wrote:

```suggestion
    if (Self.LangOpts.RTTI)
```

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


More information about the cfe-commits mailing list