GCC expects the marker comment on its own line, like this:
m_state = BODY;
// fall through
case BODY:
The marker also has to come right before the case
label; there cannot be an intervening closing brace }
.
fall through
is among the markers recognized by GCC. It's not just FALLTHRU
. For a full list, see the documentation of the -Wimplicit-fallthrough
option. Also see this posting on the Red Hat Developer blog.
C++17 adds a [[fallthrough]]
attribute that can be used to suppress such warnings. Note the trailing semicolon:
m_state = BODY;
[[fallthrough]];
case BODY:
Clang supports -Wimplicit-fallthrough
warnings, but does not enable them as part of -Wall
or -Wextra
. Clang does not recognize comment markers, so the attribute-based suppression has to be used for it (which currently means the non-standard __attribute__((fallthrough))
construct for the C front end).
Note that suppressing the warning with marker comments only works if the compiler actually sees the comment. If the preprocessor runs separately, it needs to be instructed to preserve comments, as with the -C
option of GCC. For example, to avoid spurious warnings with ccache, you need to specify the -C
flag when compiling, or, with recent versions of ccache, use the keep_comments_cpp
option.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…