GNU bug report logs - #75964
Switching the Emacs build to -Wswitch-enum in src/

Previous Next

Package: emacs;

Reported by: Pip Cet <pipcet <at> protonmail.com>

Date: Fri, 31 Jan 2025 09:41:02 UTC

Severity: wishlist

Full log


View this message in rfc822 format

From: Pip Cet <pipcet <at> protonmail.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 75964 <at> debbugs.gnu.org, stefankangas <at> gmail.com
Subject: bug#75964: Switching the Emacs build to -Wswitch-enum in src/
Date: Wed, 05 Feb 2025 20:02:47 +0000
"Paul Eggert" <eggert <at> cs.ucla.edu> writes:

> On 2025-02-05 10:10, Pip Cet wrote:
>> "Paul Eggert" <eggert <at> cs.ucla.edu> 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





This bug report was last modified 127 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.