Unreachable break in a case statement

6.15 Switch Statements

Moderators: misra-c, david ward

danielb
Posts: 1
Joined: Tue Jul 03, 2012 10:49 am
Company: OctoCode

Unreachable break in a case statement

Postby danielb » Wed Jul 04, 2012 9:14 am

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

Code: Select all

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?

misra-c
Posts: 547
Joined: Thu Jan 05, 2006 1:11 pm

Re: Unreachable break in a case statement

Postby misra-c » Wed Jul 18, 2012 9:59 am

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.
---
Posted by and on behalf of
the MISRA C Working Group


Return to “6.15 Switch Statements”

Who is online

Users browsing this forum: No registered users and 0 guests