An extraneous semicolon should be avoided to prevent an unintentional logic change

  • STRAY_SEMICOLON
  • Error
  • Medium
  • cwe

This rule applies when an extraneous semicolon causes an unintentional logic change.

Logic may be changed unintentionally due to an extraneous semicolon inserted in front of then or else part of a conditional statement or body part of a loop statement.

Noncompliant Code Example

View with compliant examples side by side
switch (x) {
case 0:
    if (y == 0); break; // STRAY_SEMICOLON alarm
case 1:
    ...
}
while (++x <= 10) ; // STRAY_SEMICOLON alarm
{
    sum += x;
}

Compliant Code Example

View with noncompliant examples side by side
switch (x) {
case 0:
    if (y == 0) break;
case 1:
    ...
}
while (++x <= 10)
{
    sum += x;
}

Version

This rule was introduced in DeepScan 1.0.0-alpha.

See