Rule A10-3-3 (required, implementation, automated)
Virtual functions shall not be introduced in a final class.
Rationale
Declaring a class as final explicitly specifies that the class cannot be inherited. Declaring a virtual function inside a class specifies that the function can be overridden in the inherited class, which is inconsistent.
Example
// $Id: A10-3-3.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
class A
{
public:
virtual ~A() = default;
virtual void F() noexcept = 0;
virtual void G() noexcept {}
};
class B final : public A
{
public:
void F() noexcept final // Compliant
{
}
void G() noexcept override // Non-compliant
{
}
virtual void H() noexcept = 0; // Non-compliant
virtual void Z() noexcept
// Non-compliant
{
}
};
See also
HIC++ v4.0 [9]: 9.1.5 Do not introduce virtual functions in a final class.