Rule Definition
The use of virtual base classes can introduce a number of undefined and potentially confusing
behaviors. Therefore, a base class shall only be declared virtual if that base class is to be used as a common base class in a diamond hierarchy.
Remediation
Do not declare the base class as virtual if not part of a diamond hierarchy
Violation Code Sample
class A {};
class D: public virtual A {}; // Non-compliant
Fixed Code Sample
//Case of diamond hierarchy
class A {};
class B1: public virtual A {}; // Compliant – A is a common base for C
class B2: public virtual A {}; // Compliant – A is a common base for C
class C: public B1, B2
Reference
MISRA C++ 2008, 10-0-1: A base class shall only be declared virtual if it is used in a diamond hierarchy
Related Technologies
Technical Criterion
CWE-1055 - Multiple Inheritance from Concrete Classes
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.