C and C++


LANG.STRUCT.EBS : Empty {Branch, for, if, switch, while} Statement

Summary

A conditional statement has only empty or nonexistent branch bodies. (Bodies may have some syntactic content, but are "semantically empty".)

Properties

Multiple warning classes share this mnemonic.

Checks for all these warning classes are enabled by default. To disable them all at once, add the following WARNING_FILTER rule to the project configuration file.

WARNING_FILTER += discard categories:LANG.STRUCT.EBS
Class Name Empty Branch Statement
Significance redundancy
Mnemonic LANG.STRUCT.EBS
Categories
CERT-C CERT-C:EXP15-C Do not place a semicolon on the same line as an if, for, or while statement
  CERT-C:MSC12-C Detect and remove code that has no effect or is never executed
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Empty Branch Statement"
Class Name Empty for Statement
Significance redundancy
Mnemonic LANG.STRUCT.EBS
Categories
CERT-C CERT-C:EXP15-C Do not place a semicolon on the same line as an if, for, or while statement
  CERT-C:MSC12-C Detect and remove code that has no effect or is never executed
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Empty for Statement"
Class Name Empty if Statement
Significance redundancy
Mnemonic LANG.STRUCT.EBS
Categories
CWE CWE:390 Detection of Error Condition Without Action
CERT-C CERT-C:EXP15-C Do not place a semicolon on the same line as an if, for, or while statement
  CERT-C:MSC12-C Detect and remove code that has no effect or is never executed
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Empty if Statement"
Class Name Empty switch Statement
Significance redundancy
Mnemonic LANG.STRUCT.EBS
Categories
CERT-C CERT-C:EXP15-C Do not place a semicolon on the same line as an if, for, or while statement
  CERT-C:MSC12-C Detect and remove code that has no effect or is never executed
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Empty switch Statement"
Class Name Empty while Statement
Significance redundancy
Mnemonic LANG.STRUCT.EBS
Categories
CERT-C CERT-C:EXP15-C Do not place a semicolon on the same line as an if, for, or while statement
  CERT-C:MSC12-C Detect and remove code that has no effect or is never executed
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Empty while Statement"

Example

int lang_struct_ebs(int a){
    int x = 1;
    if (a < 5);  /* 'Empty if Statement' warning issued here
                  * - semicolon means conditional has no effect
                  */
    {
        x = x+5;;
    }

    switch(123); // Empty switch Statement issued here

    while(0); // Empty while Statement issued here
        x++;

    for(;;); // Empty for Statement issued here
        x++;

    return x;
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.