GNU bug report logs -
#75964
Switching the Emacs build to -Wswitch-enum in src/
Previous Next
Full log
Message #146 received at 75964 <at> debbugs.gnu.org (full text, mbox):
"Stefan Monnier" <monnier <at> iro.umontreal.ca> writes:
>>> The most obvious one is to remove all the `case ..:` just before `default:`.
>>> That would be my vote as well (tho only because I don't know that
>>> code. There might be a very good reason to keep it as above, of course).
>>
>> The reason was to add -Wswitch-enum, which would warn about incomplete
>> case enumerations involving an enum type.
>
> In which sense is a "`switch` with a `default` clause" incomplete?
Only in the sense that it's sometimes useful to warn about such
statements! They're not invalid C.
GCC offers an option to do that. Disabling that option, as we had
previously done, had led to some (very minor) bugs and some potential
bugs that I have yet to look at (such as the "crash on DEFAULT_CURSOR"
thing upthread).
But it seems there is a consensus we'd rather live with such bugs, so
nothing about switch statements is about to change. It'll be perfectly
okay to continue writing code such as:
enum ABC { A, B, C };
enum ABC abc;
switch (abc) {
case A:
/* handle case A */
break;
default:
/* we know this must be case C */
/* handle case C */
break;
}
(The major problem, of course, is that case B might have to be handled
differently. The minor, much rarer problem is that abc might not be any
of A, B, or C, but a different value altogether: C + 3, for example. C
makes this legal, and Emacs relies on such behavior.)
Paul's suggestion for switching off the warning behavior is very clever,
and if he could come up with a way of switching ON the warning behavior
where we might want it, maybe that would be an option, but at this point
we need to look at the potential bugs this warning has found, then close
the bug. If it had discovered massive numbers of actual bugs I'd argue
differently, but it hasn't, so unless Paul wants to take over and argue
for this change, it lacks a champion.
We might want to disable -Wswitch, too, as it only results in a false
sense of security and useless default: clauses being added to pacify
warnings.
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.