Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC2004-14.9

In this section:
Synopsis

(Required) An if expression construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement or another if statement.

Enabled by default

Yes

Severity/Certainty

Low/Low

lowlow.png
Full description

There are missing braces in one or more if, else, or else if statements. This check is identical to MISRAC++2008-6-4-1, MISRAC2012-Rule-15.6_c.

Coding standards
CERT EXP19-C

Use braces for the body of an if, for, or while statement

CWE 483

Incorrect Block Delimitation

MISRA C:2004 14.9

(Required) An if expression construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement or another if statement.

MISRA C:2012 Rule-15.6

(Required) The body of an iteration-statement or a selection-statement shall be acompound-statement

MISRA C++ 2008 6-4-1

(Required) An if ( condition ) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement.

Code examples

The following code example fails the check and will give a warning:

void example(void) {
	if (random());
	if (random());
	else;
}

The following code example passes the check and will not give a warning about this issue:

void example(void) {
	if (random()) {
	}
	if (random()) {
	} else {
	}
	if (random()) {
	} else if (random()) {
	}
}