Rule M10-2-1 (advisory, implementation, automated)
All accessible entity names within a multiple inheritance hierarchy should be unique. See MISRA C++ 2008 [7] Rule A10-2-1 (required, implementation, automated) Non-virtual public or protected member functions shall not be redefined in derived classes.
Rationale
A non-virtual member function specifies an invariant over the hierarchy. It cannot be overridden in derived classes, but it can be hidden by a derived class member (data or function) with the same identifier. The effect of this hiding is to defeat polymorphism by causing an object to behave differently depending on which interface is used to manipulate it, resulting in unnecessary complexity and error. Note that a maintenance change to a private implementation detail could impact clients of the base class, and often it will be the case that those clients may not be in a position to fix the problem. Therefore, redefinitions of functions which are private in the base class are not affected by this rule.
Exception
Redefinition of functions from private inheritance do not violate this rule.
Example
// $Id: A10-2-1.cpp 317123 2018-04-23 08:48:11Z ilya.burylov $
class A
{
public:
virtual ~A() = default;
void F() noexcept {}
virtual void G() noexcept {}
private:
void H() noexcept {}
};
class B : public A
{
public:
void
F() noexcept {} // Non-compliant - F() function from A class hidden by B class
void G() noexcept override {} // Compliant - G() function from A class
// overridden by B class
private:
void H() noexcept {} // Compliant - H() function is private in A class
};
class C : private A
{
public:
F() noexcept {} // Compliant by exception - private inheritance
};
void Fn1(A& object) noexcept
{
object.F(); // Calls F() function from A
object.G(); // Calls G() function from B
}
void Fn2() noexcept
{
B b;
Fn1(b);
}
See also
JSF December 2005 [8]: AV Rule 94 An inherited nonvirtual function shall not be redefined in a derived class. C++ Core Guidelines [11]: ES.12: Do not reuse names in nested scopes.