MISRA C++:2023 Rule 13.3.1
User-declared member functions shall use the virtual
,
override
and final
specifiers
appropriately
Since R2024b
Description
Rule Definition
User-declared member functions shall use the virtual
,
override
and final
specifiers
appropriately.
Rationale
To make the design of a class easy to understand, this rule specifies the appropriate
use of the virtual
, override
, and
final
specifiers for user-declared member functions and destructors:
Use the specifier
virtual
if the member function is a new virtual function that does not override a function from a base class.Use the specifier
override
if the member function is a virtual function that overrides a virtual function from a base class and permits further overrides in subsequent derived classes.Use the specifier
final
if the member function is a virtual function that overrides a function from a base class and does not permit further overrides in subsequent derived classes.
Other combinations of these specifiers are permissible in the C++ standard but violate this rule because they can make the code harder to understand.
Polyspace Implementation
Polyspace® reports a violation if any of these conditions are true:
A virtual function in a derived class uses the specifier
virtual
in addition tooverride
orfinal
.A virtual function in a base class uses the specifier
override
orfinal
in addition tovirtual
.
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