MISRA C++:2023 Rule 0.2.4
Description
Rule Definition
Functions with limited visibility should be used at least once
Rationale
Functions with limited visibility are typically not meant to be called in later extensions of the current API. If such a function is left unused, it is most likely not a deliberate choice and probably indicates a programming error or an issue with the software design.
Polyspace Implementation
The rule checker reports violations on functions with limited visibility that are defined but not called within the scope where the function is visible. In particular, following the MISRA C++:2023 specifications, the rule checker reports:
Unused class member functions that are defined as
private
and notvirtual
. The checker makes an exception for the special member functions and member functions declared as=delete
.Unused unctions defined in an anonymous namespace, or defined in a class inside an anonymous namespace.
Unused functions defined as
static
in a named namespace or outside a namespace.
The checker does not report violations on:
Unused functions if the function declarations use the
[[maybe_unused]]
attribute.static inline
functions.
For overloaded functions, the checker does not report any of the overloads as long as one function in the overload set is called.
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: Language independent issues |
Category: Advisory |
Version History
Introduced in R2024b