This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/26363] New: disabling switch() default
- From: "acahalan at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Feb 2006 19:53:11 -0000
- Subject: [Bug c/26363] New: disabling switch() default
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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