2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-04-28 16:49:39 +02:00
The use of ``++virtual++`` base classes can introduce a number of undefined and potentially confusing behaviours. Therefore, a base class shall only be declared ``++virtual++`` if that base class is to be used as a common base class in a diamond hierarchy.
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-04-28 16:49:39 +02:00
----
class A {};
class B1: public virtual A {}; // Compliant, A is a common base for C
class B2: public virtual A {}; // Compliant, A is a common base for C
class C: public B1, B2 {};
class D: public virtual A {}; // Noncompliant, D is not part of a diamond-shaped hierarchy.
----
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
== Resources
2021-04-28 16:49:39 +02:00
* MISRA {cpp}:2008, 10-1-2 - A base class shall only be declared virtual if it is used in a diamond hierarchy.
2021-04-28 18:08:03 +02:00
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-09-20 15:38:42 +02:00
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Remove the "virtual" specifier on class "xxx".
2021-09-20 15:38:42 +02:00
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== on 16 Oct 2014, 13:21:54 Ann Campbell wrote:
\[~samuel.mercier] please:
* fill in the appropriate reference field(s).
* provide a See section.
* use double curly braces around code in the description
* use the standard section titles
Also, since the description references undefined behavior, I wouldn't tie this to Maintainability, but Reliability instead.
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]