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: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: acorallo <at> gnu.org, Eli Zaretskii <eliz <at> gnu.org>, eggert <at> cs.ucla.edu, 75964 <at> debbugs.gnu.org, stefankangas <at> gmail.com
Subject: bug#75964: Switching the Emacs build to -Wswitch-enum in src/
Date: Tue, 04 Feb 2025 18:28:49 +0000
"Stefan Monnier" <monnier <at> iro.umontreal.ca> writes:

>>> should return 2, because I'd prefer that it aborts and/or that the
>>> programmer have a way to say explicitly what should happen.  `default:`
>>> works for that in the case where you have listed *all* the enum's
>>> values, but then you get stiffed in the case where you add an enum value
>>> because the compiler won't tell you that you forgot to update this
>>> `switch` accordingly.
>>
>> But... that's precisely what -Wswitch-enum does!  It warns about a
>> forgotten case even though there is also a default label!
>
> But IIUC that breaks the other case, where you do want to use `default:`
> to mean "any other (valid) enum value".

That's what I meant by "not easy to turn on and off on a per-switch
basis", yes (unless you really want to learn about _Pragma).  Slightly
easier to do so on a per-enum basis, though (it has a type, types have
attributes, there's already one for bitfield enums), but that means you
need to control the enums rather than some other header file doing so.

And while statement/label atttributes are possible, they turn into
horrible macro constructions.

So while I still think -Wswitch-enum would be the best solution, it's by
a slight margin and Eli's describing the effect on bidi.c as so drastic
that we'd have to disable it for that file, and per-file CFLAGS are a
nightmare, so all we can do is wait for GCC to learn new tricks (which
I'm not smart enough to think of).

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.