public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/26363]  New: disabling switch() default
@ 2006-02-19 19:53 acahalan at gmail dot com
  2006-02-20  2:13 ` [Bug middle-end/26363] " pinskia at gcc dot gnu dot org
  2006-04-22 20:52 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: acahalan at gmail dot com @ 2006-02-19 19:53 UTC (permalink / raw)
  To: gcc-bugs

If I have listed every possible case for a switch, there is no need for a
default. The compiler generates this default anyway though, even if I don't
specify it. I'd like a way to eliminate this, such that an unhandled case
becomes undefined behavior that may well involve a crash.

(the same should of course be true if the compiler can determine for itself
that other values are impossible -- this might already work)

Perhaps this could be done via a stronger form of __builtin_expect(), which
would have plenty of other uses. This wouldn't be all that easy to use though.
Better would be something like:

default:
        __not_reached;


Another reasonable way would be:

switch __no_default(foo)

That way, a #define could put those keywords together into something like
SWITCH.


NOTE: I set the component to "c" because Bugzilla forced me to choose. I intend
for this to cover all C-like languages, not just C.


-- 
           Summary: disabling switch() default
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: acahalan at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26363


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/26363] disabling switch() default
  2006-02-19 19:53 [Bug c/26363] New: disabling switch() default acahalan at gmail dot com
@ 2006-02-20  2:13 ` pinskia at gcc dot gnu dot org
  2006-04-22 20:52 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-20  2:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-02-20 02:13 -------
I don't see why there needs to be an attribute or even cause that much missed
optimization?  GCC should be able to find that the default is not taken via VRP
but does not currently but that is a different bug that has been filed already.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26363


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/26363] disabling switch() default
  2006-02-19 19:53 [Bug c/26363] New: disabling switch() default acahalan at gmail dot com
  2006-02-20  2:13 ` [Bug middle-end/26363] " pinskia at gcc dot gnu dot org
@ 2006-04-22 20:52 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-04-22 20:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-04-22 20:52 -------
This is not really that useful, the problem comes down to if the user messes up
(which is 90% of the time anyways), they get a crash in their program and blame
GCC.  So exosing stuff like this is crazy to do really.

And getting a person to annotate their code with these attributes just get more
and crazy.  Instead it is just better to improve the optimizers instead of
adding attributes to work around the optimizers not working for your case.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WONTFIX


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26363


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-04-22 20:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-19 19:53 [Bug c/26363] New: disabling switch() default acahalan at gmail dot com
2006-02-20  2:13 ` [Bug middle-end/26363] " pinskia at gcc dot gnu dot org
2006-04-22 20:52 ` pinskia at gcc dot gnu dot org

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).