Subject: bug#75964: Switching the Emacs build to -Wswitch-enum in src/

From: Pip Cet <[email-masked]>
Date: Mon, 03 Feb 2025 21:15:38 +0000

"Stefan Monnier" <[email-masked]> writes:

>> enum ABC abc;
>> switch (abc) {
>> case A:
>>   /* handle case A */
>>   break;
>> default:
>>   /* we know this must be case C */
>>   /* handle case C */
>>   break;
>> }
>
> I think this just suggests we should refrain from using `default:`

Switching over an enum without a default: label will generate
fall-through code, for those cases in which the enum variable has a
value that's not in the enumeration.

Yes, C allows this, and requires it, and Emacs relies on this "feature"
(in at least two places, which I won't mention to protect the guilty).
That means extra code will be generated, and GCC will warn about
uninitialized data or whatever other state of things falling through the
switch statement will leave us with.

This is all very silly and hopefully C3X will introduce actual enums,
but until then, we need the default branch.

> I don't think there can be a silver bullet.

Maybe not.

Pip