Skip to main content

IAR Embedded Workbench for RH850 3.20.x

MISRAC++2008-6-3-1_c

In this section:
Synopsis

(Required) The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement.

Enabled by default

Yes

Severity/Certainty

Low/Low

lowlow.png
Full description

There are missing braces in switch statements. This check is identical to MISRAC2004-14.8_c, MISRAC2012-Rule-15.6_d.

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.8

(Required) The statement forming the body of a switch, while, do ... while, or for statement shall be a compound statement.

MISRA C:2012 Rule-15.6

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

Code examples

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

void example(void) {
	while(1);
	for(;;);
	do ;
	while (0);
	switch(0);
}

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

void example(void) {
	while(1) {
	}
	for(;;) {
	}
	do {
	} while (0);
	switch(0) {
	}
}