MISRA C++:2023 Rule 13.1.2
An accessible base class shall not be both virtual and non-virtual in the same hierarchy
Since R2024b
Description
Rule Definition
An accessible base class shall not be both virtual and non-virtual in the same hierarchy. 1
Rationale
You use virtual inheritance to prevent the creation of multiple copies of a base class
Base
subobject in a derived class that inherits class
Base
more than once through intermediate classes.
If the same class is inherited virtually and non-virtually in the same hierarchy, multiple instance of the base class subobject can exist, which might not be the intent of the developer.
Polyspace Implementation
The coding rule checker reports a violation in the declaration of the most derived class for each derived class that inherits the base class non-virtually.
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: Derived classes |
Category: Required |
Version History
Introduced in R2024b
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.