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

From: Pip Cet <[email-masked]>
Date: Wed, 05 Feb 2025 20:02:47 +0000

"Paul Eggert" <[email-masked]> writes:

> On 2025-02-05 10:10, Pip Cet wrote:
>> "Paul Eggert" <[email-masked]> writes:
>>> With an enum expression E and code like this:
>>>
>>>      switch (E) { case A: ...; case B: ...; }
>>>
>>> there is currently no compile-time diagnostic for mismatches between the
>>> type and the code when the enum type also has a value C
>
>> gcc -Wswitch-enum will warn about it, but gcc -Wswitch won't.
>
> Oh yes, my outline should have said "switch (E) { case A: ...; case B:
> ...; default; }".

Well, as it turns out, that wasn't the only thing I was confused about :-)

>> The current GCC behavior of treating a switch statement as
>> non-enumerated if the control expression isn't of enum type leads to
>> false negatives, and I'd like to change it.  Relying on it as a way to
>> disable warnings using the switch (+x) idiom seems unwise to me for that
>> reason, because we will then permanently lose those important warnings.
>
> My little proposal (and it is a little one) works better with GCC as it
> is now. If GCC is improved, we can change the code to deal with the

Sorry.  I totally missed that point!

I think if we want to do something with GCC now, your proposal seems
best, then.

Thanks!

Pip