https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120831
Bug ID: 120831 Summary: Raise a diagnostic when a class/struct that is marked as final introduces a virtual method Product: gcc Version: 15.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: arash at partow dot net Target Milestone: --- In clang++ v21, the following code correctly raises the diagnostic below: struct base { virtual ~base() = default; virtual void foo() {} }; struct derived final : public base { void foo() override {} virtual void bar() {} // raise error due to this. }; Diagnostic <source>:11:18: error: virtual method 'bar' is inside a 'final' class and can never be overridden [-Werror,-Wunnecessary-virtual-specifier] 11 | virtual void bar() {} Where the arguments are: -pedantic-errors -Wall -Wextra -Werror -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wint-in-bool-context -Wmissing-declarations -Wredundant-decls -Wundef -Wunused-function -Wnon-virtual-dtor -Woverloaded-virtual -Wno-missing-template-arg-list-after-template-kw However afaict, G++ does not provide such a diagnostic - unless I'm possibly missing the appropriate option. It should be noted that the -Wunnecessary-virtual-specifier seems to, for now, be clang++ specific. https://godbolt.org/z/rPG6r8EPa