MISRA C++:2008 Rule 7-1-1
A variable which is not modified shall be const qualified
Description
Rule Definition
A variable which is not modified shall be const qualified.1
Rationale
Declaring a variable const
reduces the chances that you modify the
variable inadvertently.
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: Declarations |
Category: Required |
Version History
Introduced in R2018a1 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.