[Bug c/26363] New: disabling switch() default

acahalan at gmail dot com gcc-bugzilla@gcc.gnu.org
Sun Feb 19 19:53:00 GMT 2006


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



More information about the Gcc-bugs mailing list