MISRAC2012-Rule-10.1_R8
Synopsis
(Required) Operands shall not be of an inappropriate essential type. An operand of essentially unsigned typed is used as the operand to the unary minus operator. This is problematic because the signedness of the result is determined by the implementation-defined size of int.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
An operand of essentially unsigned typed is used as the operand to the unary minus operator. This check is identical to MISRAC++2008-5-3-2, MISRAC2004-12.9, MISRAC++2023-8.3.1.
Coding standards
- MISRA C:2004 12.9
(Required) The unary minus operator shall not be applied to an expression whose underlying type is unsigned.
- MISRA C++ 2008 5-3-2
(Required) The unary minus operator shall not be applied to an expression whose underlying type is unsigned.
- MISRA C++ 2023 8.3.1
(Advisory) The built-in unary - operator should not be applied to an expression of unsigned type
Code examples
The following code example fails the check and will give a warning:
void example(void) {
unsigned int max = -1U;
// use max = ~0U;
}
The following code example passes the check and will not give a warning about this issue:
void example(void) {
int neg_one = -1;
}