MISRAC++2023-8.0.1
In this section:
Synopsis
(Advisory) Parentheses should be used to make the meaning of an expression appropriately explicit
Enabled by default
No
Severity/Certainty
Medium/Medium

Full description
Parentheses to avoid implicit operator precedence are missing. This check is identical to MISRAC++2008-5-0-2, MISRAC2004-12.1, MISRAC2012-Rule-12.1.
Coding standards
- MISRA C:2004 12.1
(Advisory) Limited dependence should be placed on the C operator precedence rules in expressions.
- MISRA C:2012 Rule-12.1
(Advisory) The precedence of operators within expressions should be made explicit
- MISRA C++ 2008 5-0-2
(Advisory) Limited dependence should be placed on C++ operator precedence rules in expressions.
Code examples
The following code example fails the check and will give a warning:
void example(void) {
int i;
int j;
int k;
int result;
result = i + j * k;
}
The following code example passes the check and will not give a warning about this issue:
void example(void) {
int i;
int j;
int k;
int result;
result = i + (j - k);
}