MISRA C++:2008 Rule 10-3-3
A virtual function shall only be overridden by a pure virtual function if it is itself declared as pure virtual
Description
Rule Definition
A virtual function shall only be overridden by a pure virtual function if it is itself declared as pure virtual.1
Rationale
In C++, an abstract class is the base of a polymorphic class hierarchy and the derived classes implement variation of the abstract class. When a virtual function is overridden in a derived class by a pure virtual function, the derived class becomes an abstract class. That a derived class is defined as an abstract class or an implemented function is overridden by a pure virtual function is unexpected behavior, which might confuse a developer.
Polyspace Implementation
Polyspace® flags a pure virtual function if it overrides a function that is not pure virtual.
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 R2013b
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.