MISRA C:2012 Rule 23.5
A generic selection should not depend on implicit pointer type conversion
Since R2024a
Description
Rule Definition
A generic selection should not depend on implicit pointer type conversion.
This rule comes from MISRA C™: 2012 Amendment 3.
Rationale
The controlling expression of a generic selection undergoes an lvalue conversion and then the type of the converted value is compared to the types in the association list. Unless an exact match is found, the default association is selected. The compiler makes no attempt to implicitly convert the type of the controlling expression to match any of the nondefault association. If you implement a generic function using generic association, the argument of the generic function does not undergo implicit conversion, unlike with nongeneric C functions. This behavior can be unexpected and can produce incorrect results.
Polyspace Implementation
The rule checker reports a violation if the compiler performs an implicit pointer conversion between the type of the controlling expression and the type of the default association. If your selection is not based on pointer types, the rule checker does not report a violation.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Generic Selections |
Category: Advisory |
AGC Category: Advisory |
Version History
Introduced in R2024a