This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53960] New: Add warning about implicit fallthrough in switch
- From: "david at doublewise dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 14 Jul 2012 04:35:34 +0000
- Subject: [Bug c++/53960] New: Add warning about implicit fallthrough in switch
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53960
Bug #: 53960
Summary: Add warning about implicit fallthrough in switch
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: david@doublewise.net
A helpful warning that should catch real bugs would be to warn for cases of
implicit fallthrough in a switch statement in C / C++. This warning is
currently implemented in clang. However, I feel that their implementation is
flawed, and we can do it a little better. It is idiomatic C / C++ to do
something like this, which should not be warned about:
switch(n) {
case 0:
case 1: // Implicit fallthrough, but obviously intended
do_something();
break;
default:
break;
}
Perhaps we should add two sets of warnings? Something like
-Wimplicit-fall-through and -Wimplicit-fall-through-empty-case? The second
warning would be identical to the clang warning, which warns whenever a case in
a switch does not end in something like break or return, while the first
warning is the (much more useful) warning only if a case is not completely
empty.