I guess the exception is not where you wanted it to be. Maye in a default label?
Adding -Wswitch force to cover all cases of all enumerations. This has consequences, especially in existing code base. It would be OK for a new project.
For a simple if/else with a single bool parameter, using a switch case would be fine. But there are other cases, more complex, where the solution won't be that easy.
Examples:
voidsearchLocation(boolaccessible){puts(accessible?"yes it is":"no it isn't");}boolfunction(boolA,boolB,boolC){return(AandB)or(notBandC)or(notA);}
I think you get my point: a two-value enum isn't a boolean. It can be nice in public API. It's not always friendly for implementers.
The exception is exactly at the place I wanted it to be. And exactly because of the warnings it would introduce in existing codebases. As such, I can either make it clearer or actually find and fix/document bugs.
I agree that it's not always straightforward.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Replace the
if
s with aswitch
.I guess the exception is not where you wanted it to be. Maye in a default label?
Adding -Wswitch force to cover all cases of all enumerations. This has consequences, especially in existing code base. It would be OK for a new project.
For a simple if/else with a single bool parameter, using a switch case would be fine. But there are other cases, more complex, where the solution won't be that easy.
Examples:
I think you get my point: a two-value enum isn't a boolean. It can be nice in public API. It's not always friendly for implementers.
The exception is exactly at the place I wanted it to be. And exactly because of the warnings it would introduce in existing codebases. As such, I can either make it clearer or actually find and fix/document bugs.
I agree that it's not always straightforward.