MISRA.SWITCH.NOT_WELL_FORMEDSwitch statement is not well-formed. MISRA-C++ Rule 6-4-3 (required): A switch statement shall be a well-formed switch statement.A well-formed switch statement conforms to the following syntax rules, which are additional to the C++ standard syntax rules. All syntax rules not defined below are as defined in ISO/IEC 14882:2003 [1]. switch-statement:
case-label-clause-list:
case-label:
case-clause:
default-label-clause:
default-label:
default-clause:
case-block:
case-block-seq:
The following statements, which are permitted by C++, are explicitly not included within the MISRA C++ switch syntax rules. Note, however, that they are permitted within the compound statements forming the body of a switch-clause.
The following terms are also used within the text of the rules: switch-label Either a case-label or default-label. case-clause The code between any two switch-labels. default-clause The code between the default-label and the end of the switch statement. switch-clause Either a case-clause or a default-clause. RationaleThe syntax for the switch statement in C++ is weak, allowing complex, unstructured behaviour. The previous text describes the syntax for switch statements as defined by MISRA C++. This, and the associated rules, imposes a simple and consistent structure on to the switch statement. Exampleswitch ( x ) { case 0: ... break; // break is required here case 1: // empty clause, break not required case 2: break; // break is required here default: // default clause is required break; // break is required here, in case a future // modification turns this into a case clause } |