I would start with the basics and give the class a virtual
destructor: compilers tend to warn about that.
With respect to the actual question, it is highly unlikely that the use of override
will be made mandatory as there is way too much code in existence which would need to get patched up. The general view taken by the standards committee on issues like these is that it is a quality of implementation issue: compilers are entirely free to warn about all sorts of potentially problematic declaration. That is, you'd lobby your compiler vendor or your static analyzer vendor to create a warning for this situation. ... and if you don't think you can make the vendors apply the check, create it yourself! Checking whether there is an override
keyword when overriding a virtual
function using, e.g., clang is fairly simple.
Also, here is an example where a mandatory use of override
would not work:
struct Base1 {
virtual ~Base1() {}
virtual int f() { return 0; }
};
struct Base2 {
int f() { return 1; }
};
template <typename Base>
struct Derived: Base {
int f() { return 2; }
};
int main()
{
Derived<Base1> d1;
Derived<Base2> d2;
}
In the class template Derived
the function f()
may or may not be an override. You can't conditionally put override
there.