]> xenbits.xensource.com Git - people/andrewcoop/xen.git/commitdiff
docs/misra: add Rule 16.4
authorStefano Stabellini <sstabellini@kernel.org>
Thu, 14 Mar 2024 21:50:21 +0000 (14:50 -0700)
committerStefano Stabellini <stefano.stabellini@amd.com>
Tue, 16 Apr 2024 19:15:16 +0000 (12:15 -0700)
Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
Acked-by: Bertrand Marquis <bertrand.marquis@arm.com>
docs/misra/rules.rst

index d3159af9172e5da7154eeafa582381975fb6c73f..b7b447e1524f63b9675908c08d8a5a8c8c515f17 100644 (file)
@@ -494,6 +494,31 @@ maintainers if you want to suggest a change.
      - In addition to break, also other unconditional flow control statements
        such as continue, return, goto are allowed.
 
+   * - `Rule 16.4 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_16_04.c>`_
+     - Required
+     - Every switch statement shall have a default label
+     - Switch statements with enums as controlling expression don't need
+       a default label as gcc -Wall enables -Wswitch which warns (and
+       breaks the build as we use -Werror) if one of the enum labels is
+       missing from the switch.
+
+       Switch statements with integer types as controlling expression
+       should have a default label:
+
+       - if the switch is expected to handle all possible cases
+         explicitly, then a default label shall be added to handle
+         unexpected error conditions, using BUG(), ASSERT(), WARN(),
+         domain_crash(), or other appropriate methods;
+
+       - if the switch is expected to handle a subset of all possible
+         cases, then an empty default label shall be added with an
+         in-code comment on top of the default label with a reason and
+         when possible a more detailed explanation. Example::
+
+             default:
+                 /* Notifier pattern */
+                 break;
+
    * - `Rule 16.2 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_16_02.c>`_
      - Required
      - A switch label shall only be used when the most closely-enclosing