Rule A10-3-2 (required, implementation, automated)

Each overriding virtual function shall be declared with the override or final specifier.

Rationale

Explicit use of the override or final specifier enables the compiler to catch mismatch of types and names between base and derived classes virtual functions. Note that this rule applies to virtual destructor overriders, too. Also, note that this rule applies to a pure virtual function which overrides another pure virtual function.

Example

// $Id: A10-3-2.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
class A
{

public:
virtual ~A() {}
virtual void F() noexcept = 0;
virtual void G() noexcept {}
virtual void Z() noexcept {}
virtual A& operator+=(A const& oth) = 0;

};
class B : public A
{
public:
~B() override {}
// Compliant
void F() noexcept // Non-compliant
{
}
virtual void G() noexcept // Non-compliant
{
}
void Z() noexcept override // Compliant
{
}
B& operator+=(A const& oth) override // Compliant
{
return *this;

}

};
class C : public A
{
public:
~C() {}
// Non-compliant
void F() noexcept override // Compliant
{
}
void G() noexcept override // Compliant
{
}
void Z() noexcept override // Compliant
{
}
C& operator+=(A const& oth) // Non-compliant
{
return *this;

}

};

See also

HIC++ v4.0 [9]: 10.2.1 Use the override special identifier when overriding a virtual function C++ Core Guidelines [11]: C.128: Virtual functions should specify exactly one of virtual, override, or final.