MISRA Discussion Forums
Unreachable break in a case statement - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.15 Switch Statements (https://forum.misra.org.uk/forumdisplay.php?fid=45)
+---- Thread: Unreachable break in a case statement (/showthread.php?tid=906)



Unreachable break in a case statement - danielb - 04-07-2012

I have recently come across two different rule interpretations of the following code:

Code:
switch(cond)
{
  case 0:
  {
    /* A deliberate infinite loop. */
    for ( ; ; ) { }
    
    /* Unreachable break statement. */
    break;
  }
  [ … ]
}
One MISRA checker insists on the break statement referring to rule 15.2, while the other insists that the break statement is unreachable code according to rule 14.1.

Both rules are required, however, both can not be enforced in this case. Which rule supersedes the other?


Re: Unreachable break in a case statement - misra-c - 18-07-2012

In situations such as this, Rule 15.2 takes priority. So, the break statement shall be present and a deviation needs to be raised against Rule 14.1 justifying the unreachability of the break.