[previous] 2003 [next] The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
Switch statements

The preceding non-empty case clause is not terminated with a jump statement. Is this intended ?

It is very easy to overlook "fall-through" situations such as this when reviewing 'switch' statements. If this is the intended behaviour, it is advisable to insert a comment in order to confirm the intention.

Message 2003 is generated whenever a 'case' label is preceded by a clause which is not terminated with either a 'break', a 'return', a 'continue' or a 'goto' statement.

For example:


/*PRQA S 2017,3120,3227,3408 ++*/

extern int foo(int value)
{
    int r = 2;

    switch (value)
    {
    case 1:
        r = 10;

    case 2:                             /* Message 2003 */
        ++r;
        break;

    case 3:                             /* Empty clause - fall through allowed */
    case 4:
        r = 20;
        break;

    default:
        r = 30;
        break;
    }

    return r;
}


MISRA C:2012 Rules applicable to message 2003:

Rule-16.3  (Required) An unconditional break statement shall terminate every switch-clause


See also:

QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents