This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/53960] New: Add warning about implicit fallthrough in switch


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]