On 23.04.2024 12:02, Federico Serafini wrote:
> --- a/docs/misra/deviations.rst
> +++ b/docs/misra/deviations.rst
> @@ -302,6 +302,19 @@ Deviations related to MISRA C:2012 Rules:
> leave such files as is.
> - Tagged as `deliberate` for ECLAIR.
>
> + * - R16.4
> + - Switch statements having a controlling expression of enum type
> + deliberately do not have a default case: 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.
> + - Tagged as `deliberate` for ECLAIR.
> +
> + * - R16.4
> + - A switch statement with a single switch clause and no default label
> may
> + be used in place of an equivalent if statement if it is considered to
> + improve readability."
First a terminology related comment here: I'm afraid "switch clause" can be
interpreted multiple ways, when I think we want to leave no room for
interpretation here. It's not even clear to me whether
switch ( x )
{
case 1: case 2: case 3: case 4:
...
break;
}
would be covered by the deviation, or whether the multiple case labels
wouldn't already be too much.
And then it is not clear to me why
switch ( x )
{
case 1:
...
break;
default:
...
break;
}
shouldn't also be covered, as potentially a readability improvement /
future change simplification over
if ( x == 1 )
{
...
}
else
{
...
}
Jan