AUTOSAR C++14 Rule M5-2-12
An identifier with array type passed as a function argument shall not decay to a pointer
Description
Rule Definition
An identifier with array type passed as a function argument shall not decay to a pointer.
Rationale
When you pass an array to a function as a pointer, the size information of the array becomes lost. Losing information about the array size might lead to confusion and unexpected behavior.
Avoid passing arrays as pointers to function. To pass arrays into a function,
encapsulate the array into a class object and pass the object to functions. Starting in
C++11, the standard template library implements several container classes that can be used
to pass an array to a function. C++20 has the class std::span
, which
preserves the size information.
Polyspace Implementation
Polyspace® raises a violation when you use an array in a function interface.
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: Expressions |
Category: Required, Automated |
Version History
Introduced in R2019a