Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC++2023-9.3.1_e

In this section:
Synopsis

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

Enabled by default

Yes

Severity/Certainty

Low/Low

lowlow.png
Full description

A while statement shall have a body This check is identical to MISRAC++2008-6-3-1_d, MISRAC2004-14.8_d, MISRAC2012-Rule-15.6_e.

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

MISRA C++ 2008 6-3-1

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

Code examples

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

int example(void) {
  while (1)
    return 0;
}

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

int example(void) {
  while (1) {
    return 0;
  }
}