AUTOSAR C++14 Rule A7-1-1
Constexpr or const specifiers shall be used for immutable data declaration
Since R2020b
Description
Rule Definition
Constexpr or const specifiers shall be used for immutable data declaration.
Rationale
Declaring a variable const
or constexpr
reduces
the chances that you modify the variable by accident. In addition, compilers can perform
various optimizations on const
and constexpr
variables
to improve run-time performance.
Polyspace Implementation
The checker flags:
Function parameters or local variables that are not const-qualified but never modified in the function body.
Pointers that are not const-qualified but point to the same location during its lifetime.
Function parameters of integer, float, enum, and Boolean types are not flagged.
If a variable is passed to another function by reference or pointers, the checker assumes that the variable can be modified. These variables are not flagged.
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: Declaration |
Category: Required, Automated |