MISRAC2004-16.7
In this section:
Synopsis
(Required) A pointer parameter in a function prototype should be declared as pointer to const if the pointer is not used to modify the addressed object.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
A function was found that does not modify one of its parameters. This check is identical to MISRAC++2008-7-1-2, MISRAC++2023-10.1.1.
Coding standards
- MISRA C++ 2008 7-1-2
(Required) A pointer or reference parameter in a function shall be declared as pointer to const or reference to const if the corresponding object is not modified.
- MISRA C++ 2023 10.1.1
(Advisory) The target type of a pointer or lvalue reference parameter should be const-qualified appropriately
Code examples
The following code example fails the check and will give a warning:
int example(int* x) { //x should be const
if (*x > 5){
return *x;
} else {
return 5;
}
}
The following code example passes the check and will not give a warning about this issue:
int example(const int* x) { //OK
if (*x > 5){
return *x;
} else {
return 5;
}
}