Commits
Juris Lambda authored c487db5b9f8
.......... [DEV-3919] enabled warning about missing default switch cases
-Wswitch is enabled by -Wall[1][2]. It makes the compiler emit warnings
when (1) a switch is given an enumerator variant for the index, and the
case labels don't exhaustively cover all variants, and (2) when the
given switch index is an enumerator type, but its value is not one of
the enumerator's values[n1].
Warnings from (1) can be suppressed by providing a `default` case, i.e.:
switch (index)
{
case VARIANT1:
/* ... */
break;
case VARIANT2:
/* ... */
break;
default:
/* DO NOTHING */
break;
}
-Wswitch-default warns only about missing `default` switch case labels
(regardless if case labels exhaust the whole enumerator value range),
while -Wswitch-enum causes a warning to be emitted when the labels don't
exhaust the enumerator value range, even with a `default` case present.
The latter is suppressed by explicitly handling all the enumerator
variants in the switch. In cases where only a subset of the enumerators
values should require additional processing, the others can be grouped
with the default case, i.e.:
switch (index)
{
case VARIANT1:
/* ... */
break;
case VARIANT2:
/* ... */
break;
case VARIANT3:
case VARIANT4:
default:
/* DO NOTHING */
break;
}
Seeing as we're enabling -Wswitch-enum, may as well have
-Wswitch-default be present. Depending on the compiler, its version, and
the warning flag combination, the switch may or may not be caught by the
general -Wswitch. Regardless, this won't make much of a difference.
--
[1]: https://clang.llvm.org/docs/DiagnosticsReference.html#wswitch
[2]: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wswitch
[n1]: Even when a `default` label is present.