MISRA C++:2023 Rule 15.1.2
All constructors of a class should explicitly initialize all of its virtual base classes and immediate base classes
Since R2024b
Description
Rule Definition
All constructors of a class should explicitly initialize all of its virtual base classes and immediate base classes.
Rationale
Class inheritance hierarchies can be complex and can introduce confusion around which constructors are called and in what order. If a class has immediate and virtual base classes, the user-provided constructors of the derived class that are not defaulted should explicitly initialize the base classes to clarify which constructor is used and with what parameters.
This rule does not apply to empty classes where there is nothing to initialize. A class is empty if all of these are true:
The class has no nonstatic data members.
The class has no virtual member functions.
The class has no virtual base classes.
The class has only empty base classes.
Polyspace Implementation
The coding rule checker reports a violation if the constructor of a derived class does not explicitly initialize all nonempty immediate base classes and virtual base classes using member initialization list or by delegating to a compliant constructor.
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Special member functions |
Category: Advisory |
Version History
Introduced in R2024b