I have a complicated switch
statement, and I forgot to put a break
at the end of one of the case
s. This is quite legal, and as a resu
This check is available in Cppcheck, a free static analyser for C and C++ code. The check is currently marked "experimental", so you will need to use the --experimental
command line switch to turn it on.
This check warns against a nonempty case clause that falls through to the next case without a control flow statement such as break
, continue
, return
, etc, unless there is a comment with wording such as // fall through
immediately preceding the next case
.
You can get an idea for the kinds of constructs this handles by having a look at the switchFallThroughCase test cases in the source code.