C and C++


LANG.TYPE.BCV : Virtual Base Class

Summary

A class is derived from a virtual base class.

The MISRA C++:2008 guidelines discourage use of virtual base classes because they are associated with undefined behaviors and can be confusing for human readers.

This class is a strict superset of Virtual Base Class not In Diamond and of Implicit Inheritance from Stateful Virtual Base.

Properties

Class Name Virtual Base Class
Significance style
Mnemonic LANG.TYPE.BCV
Categories
AUTOSARC++14 AUTOSARC++14:M10-1-1 Classes should not be derived from virtual bases.
MisraC++2008 MisraC++2008:10-1-1 Classes should not be derived from virtual bases.
MisraC++2023 MisraC++2023:13.1.1 Classes should not be inherited virtually
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and require the unnormalized C ASTs for the project. To enable them, add the following WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Virtual Base Class"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

class Base {};

class DerivedPublicVirtual: public virtual Base {};  // 'Virtual Base Class' warning issued here

class DerivedVirtual: virtual Base {};               // 'Virtual Base Class' warning issued here

class DerivedPublic: public Base {};                                  // ok: base class is not virtual

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.