[clang] Warn about virtual methods in `final` classes (PR #131188)

Devon Loehr via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 14 12:28:52 PDT 2025


================
@@ -2706,6 +2706,9 @@ def warn_final_dtor_non_final_class : Warning<
   InGroup<FinalDtorNonFinalClass>;
 def note_final_dtor_non_final_class_silence : Note<
   "mark %0 as '%select{final|sealed}1' to silence this warning">;
+def warn_unnecessary_virtual_specifier : Warning<
+  "virtual method %0 is inside a 'final' class and can never be overridden">,
+  InGroup<WarnUnnecessaryVirtualSpecifier>, DefaultIgnore;
----------------
DKLoehr wrote:

My intention is to go through and try to clean up all the instances where it triggers in a followup PR, so we wouldn't have this one clogged with lots of tiny changes in random files. I agree it should be on by default.

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


More information about the cfe-commits mailing list