Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC++2023-8.3.1

In this section:
Synopsis

(Advisory) The built-in unary - operator should not be applied to an expression of unsigned type

Enabled by default

No

Severity/Certainty

Low/Medium

lowmedium.png
Full description

Uses of unary minus on unsigned expressions were found. This check is identical to MISRAC++2008-5-3-2, MISRAC2004-12.9, MISRAC2012-Rule-10.1_R8.

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:2012 Rule-10.1

(Required) Operands shall not be of an inappropriate essential type

MISRA C++ 2008 5-3-2

(Required) The unary minus operator shall not be applied to an expression whose underlying type is unsigned.

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;
}