C and C++


LANG.TYPE.IISVB : Implicit Inheritance from Stateful Virtual Base

Summary

A class is derived from a virtual stateful base class through indirect inheritance only.

We say a class is stateful if it has at least one data member.

This class is a strict subset of Virtual Base Class.

Properties

Class Name Implicit Inheritance from Stateful Virtual Base
Significance style
Mnemonic LANG.TYPE.IISVB
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
JSF++ JSF++:88.1 A stateful virtual base shall be explicitly declared in each derived class that accesses it.
Availability Available for C++ only (not 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="Implicit Inheritance from Stateful Virtual Base"
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

struct A { int a; };                          // A has a data member so is considered "stateful".

struct B : virtual A {};
struct C : virtual A {};

struct D : B {}; // 'Implicit Inheritance from Stateful Virtual Base' warning issued here
                 // - inherits 'virtual A' indirectly only

struct E: C, virtual A {};                     // ok: inherits 'virtual A' directly (and indirectly)

struct F : D, E {}; // 'Implicit Inheritance from Stateful Virtual Base' warning issued here
                    // - inherits 'virtual A' indirectly but not directly

struct G : D, E, virtual A {};                // ok: inherits 'virtual A' directly (and indirectly)

Relevant Configuration File Parameters

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