switch statement should not have duplicate case clauses

  • DUPLICATE_CASE
  • Error
  • Medium
  • No tags

This rule applies when switch statement has duplicate case clauses.

Later clause is ignored and it is likely that a programmer copied a clause but forgot to change.

Noncompliant Code Example

View with compliant examples side by side
switch (x) {
case '1':
    e += 'case';
    break;
case '1': // DUPLICATE_CASE alarm
    e += 'another case';
    break;
}

Compliant Code Example

View with noncompliant examples side by side
switch (x) {
case '1':
    e += 'case';
    break;
case '2':
    e += 'another case';
    break;
}

Version

This rule was introduced in DeepScan 1.0.0-alpha.

See

  • MISRA C:2012, Rule 2.1: A project shall not contain unreachable code

Was this documentation helpful?