Miscellaneous-NoDiamondInheritanceΒΆ

Do not introduce a non-virtual diamond inheritance

Required inputs: IR

Non-virtual diamond inheritance causes each object of the derived class to contain multiple copies of the base class. This can lead to confusing behavior, especially if the base class contains mutable state.

Avoid diamond inheritance when possible. If the derived class is intended to have multiple copies of the base class, prefer composition over inheritance. If the derived class should have only one copy of the base class, use virtual inheritance.

Possible Messages

Key

Text

Severity

Disabled

nonvirtual_diamond_inheritance

Use of non-virtual diamond inheritance.

None

False

Options