Add -Werror=switch and -Wcovered-switch-default

Authored by aaronpuchert on Nov 28 2017, 11:32 PM.



The former ensures that switch statements are adapted when an
enumeration is changed. The latter encourages to remove the default
label in fully covered switch statements, making the former more
effective. (It is silenced by default labels.)

Diff Detail

R32 KDevelop
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.
aaronpuchert requested review of this revision.Nov 28 2017, 11:32 PM
aaronpuchert created this revision.
apol added a subscriber: apol.Nov 29 2017, 12:25 AM

Then fix the warnings that appear? Or doesn't it show any issues?

There are no issues with -Wswitch, but some with -Wcovered-switch-default.

Sometimes people cast integers to enumeration types without checking whether it's a valid enumeration value first. So it might not be easy so safely fix all issues that arise. But I'll see what I can do.

Fix -Wcovered-switch-default where it is safe to do so.

mwolff accepted this revision.Nov 30 2017, 9:42 AM
mwolff added a subscriber: mwolff.

just to make this clear: are there any remaining new compiler warnings? if so, fix them first. otherwise lgtm

This revision is now accepted and ready to land.Nov 30 2017, 9:42 AM

Fix remaining occurences of -Wcovered-switch-default.

No functional change intended.

@mwolff Are the additional changes Ok? There are no new warnings anymore.

I used Q_UNREACHABLE() when the enumeration was used safely and a fallback when unchecked static_casts were involved. In an ideal world, I would probably try to make sure that enumerations only ever have valid values, but right now I don't understand enough of the code base to properly fix this.

aaronpuchert added inline comments.Dec 19 2017, 7:54 PM

I'm not sure this is intentional, but I'm going to leave it for now. I promised no functional change.

This revision was automatically updated to reflect the committed changes.