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.
1
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
virtualif the member function is a new virtual function that does not override a function from a base class.Use the specifier
overrideif 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
finalif 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
virtualin addition tooverrideorfinal.A virtual function in a base class uses the specifier
overrideorfinalin 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
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.