* -Wswitch and default case
@ 2001-11-14 2:59 Tom Tromey
2001-11-14 21:19 ` Hartmut Schirmer
2001-11-15 6:32 ` Alexandre Oliva
0 siblings, 2 replies; 4+ messages in thread
From: Tom Tromey @ 2001-11-14 2:59 UTC (permalink / raw)
To: gcc
I've run into a case where I'd like to use -Wswitch but also have a
default case in my switch.
Suppose I have a switch for something like a bytecode interpreter (my
actual situation is the Java bytecode verifier). I have a large
number of bytecodes, which are in an enum. I'd like to make sure I
don't forget one of the opcodes in one of my switches, so I'd like to
use -Wswitch. But at the same time if there is a bogus bytecode, I'd
like to catch that in a `default' case. Unfortunately the presence of
a default case eliminates whatever utility -Wswitch might have
provided.
I know somebody has wanted this before:
http://gcc.gnu.org/ml/gcc/2000-11/msg00854.html
Has anybody tried to implement this change?
If not I'll submit a feature request.
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: -Wswitch and default case
2001-11-14 2:59 -Wswitch and default case Tom Tromey
@ 2001-11-14 21:19 ` Hartmut Schirmer
2001-11-15 6:32 ` Alexandre Oliva
1 sibling, 0 replies; 4+ messages in thread
From: Hartmut Schirmer @ 2001-11-14 21:19 UTC (permalink / raw)
To: Tom Tromey; +Cc: gcc
On Fri, 23 Nov 2001, Tom Tromey wrote:
>I've run into a case where I'd like to use -Wswitch but also have a
>default case in my switch.
>
[...]
>Has anybody tried to implement this change?
>If not I'll submit a feature request.
I like this feature. It´s hard to write robust code
in C using enum´s and switches and gcc diagnostic could
be much better here.
One could introduce a command line option like -Wswitch-all
or/and enable this option in the source for every default that
should be hidden by adding an attribute to default or use a
special version like __default / __silent_default / ...
Hartmut
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: -Wswitch and default case
2001-11-14 2:59 -Wswitch and default case Tom Tromey
2001-11-14 21:19 ` Hartmut Schirmer
@ 2001-11-15 6:32 ` Alexandre Oliva
1 sibling, 0 replies; 4+ messages in thread
From: Alexandre Oliva @ 2001-11-15 6:32 UTC (permalink / raw)
To: tromey; +Cc: gcc
On Nov 23, 2001, Tom Tromey <tromey@redhat.com> wrote:
> Has anybody tried to implement this change?
Not as far as I know.
> If not I'll submit a feature request.
I suggest making the default: label with attribute((unused)) would be
a reasonable way to tell the compiler that (i) the default is not
supposed to be used very often (which helps us get better code from
basic-block reordering and branch probability analysis) and (ii) it's
there just to catch erroneous cases, so the compiler should still warn
if any of the enum members doesn't have a corresponding case. Hmm,
but perhaps this is overloading attribute((unused)) too much?
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me
^ permalink raw reply [flat|nested] 4+ messages in thread
* -Wswitch and default case
@ 2001-11-14 17:08 Claus Fischer
0 siblings, 0 replies; 4+ messages in thread
From: Claus Fischer @ 2001-11-14 17:08 UTC (permalink / raw)
To: gcc
It would be nice to have such a warning (reporting missing
cases in the presence of the default: label) but it should
be distinct from -Wswitch, IMHO. Give it a separate name,
if you do it.
Claus
--
Claus Fischer <claus.fischer@clausfischer.com>
http://www.clausfischer.com/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2001-11-25 2:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-14 2:59 -Wswitch and default case Tom Tromey
2001-11-14 21:19 ` Hartmut Schirmer
2001-11-15 6:32 ` Alexandre Oliva
2001-11-14 17:08 Claus Fischer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).