Issue |
148856
|
Summary |
`-Wswitch-default` and `-Wswitch-enum` warning behaviour change request
|
Labels |
new issue
|
Assignees |
|
Reporter |
r-barnes
|
# Goals
We have a large codebase with many switches. `-Wimplicit-fallthrough`, `-Wunreachable-code-break`, and `-Wunreachable-code-fallthrough` have been invaluable for improving the safety of this code pattern.
We're thinking about switch cases now and the existing set of flags is proving unwieldy, as described below. Modifications to the behaviour of these flags would allow us to improve safety where it's needed most while leaving otherwise functional code unaltered.
# Existing behaviours
`-Wswitch-default` requires that _all_ switches have a default, even if they cover all of their enum values. Satisfying this flag in a large project may require adding many `default: std::unreachable()` or similar to the codebase.
`-Wswitch-enum` requires that _all_ enum switches list every enum value, even if they have a default. This, again, creates a lot of code noise.
# Desired behaviours
**`-Wswitch-default`**
I think it would be better if `-Wswitch-default` triggered only in situations where not all the switch cases are covered. The new warning message would be:
> warning: ‘switch’ doesn't explicitly handle all cases and is missing a ‘default’ label
A new flag `-Wswitch-default-strict` would cover the old behaviour: explicitly requiring `default` everywhere.
**`-Wswitch-enum`**
`-Wswitch-enum` should interpret `default` as covering enum all enum cases that aren't otherwise handled. `-Wswitch-enum-strict` would capture the old behaviour and require that all cases be listed explicitly, even if a default is present.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs