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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 27 11:26:18 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;
----------------
erichkeane wrote:

Is there value to some sort of 'note' where we point out where the inheritence happened?  Though printing the whole inheritence list is probably pretty awful.

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


More information about the cfe-commits mailing list