This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/7652] -Wswitch-break : Warn if a switch case falls through
- From: "brendan at zen dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 Jul 2004 09:43:03 -0000
- Subject: [Bug c/7652] -Wswitch-break : Warn if a switch case falls through
- References: <20020820073602.7652.ac131313@redhat.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From brendan at zen dot org 2004-07-29 09:43 -------
An alternative between "warn about all fall-throughs" and "never do it" would
be quite useful. If you have
case 0:
case 1:
foo();
default:
bar();
gcc could warn only on the 'case 1' line, since it will see that there are
statements between it and the default beneath it without a 'break' intervening.
The fact that 'case 0' falls into 'case 1' won't be warned, since there are no
actions between them.
Most of the time, users will have a good reason to do multiple cases, but less
often will someone want
case 0:
bar(i);
case 1:
foo(i);
break;
For those instances, they'll probably not be using -Wswitch-break (defaulting
to off) anyway. At any rate, it'll much more common to make the mistake of
omitting the break, compared to coding it to have statements between cases
without 'break'. My opinion, anyway.
B
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652