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: Andrea Corallo <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: Mon, 03 Feb 2025 21:15:38 +0000
"Stefan Monnier" <monnier <at> iro.umontreal.ca> 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





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.