Expand description
final-misplaced — final on a function that is neither virtual nor overriding.
struct Widget {
void size() final; // error: `final` may only be applied to a virtual function
virtual void draw() final; // fine: virtual, so `final` is what it says
};
struct Base { virtual void run(); };
struct Derived : Base { void run() final; }; // fine: overrides `Base::run`[class.mem.general] allows virt-specifier-seq only where the function is virtual — either because it says
virtual itself or because it overrides one — so a final on an ordinary member function is ill-formed.
§Only what is certain
`virtual` is written -> silent: `virtual … final` is legal
the class has no base -> report: nothing can be overridden
a base names it, and one of them is virtual -> silent: this is an override
a base could not be read -> silent
no base names it, every base was read -> reportThe last row is the one that needs care: a base with a member of the same name that is not virtual could be a
different overload, and the signature is not compared here (see super::override_nonexistent for why), so only
the definite shape — no base names it at all — is reported.
Structs§
- Final
Misplaced final-misplaced— see the module documentation.