This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/77817] New: -Wimplicit-fallthrough: cpp directive renders FALLTHRU comment ineffective
- From: "jim at meyering dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 02 Oct 2016 14:33:38 +0000
- Subject: [Bug c/77817] New: -Wimplicit-fallthrough: cpp directive renders FALLTHRU comment ineffective
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77817
Bug ID: 77817
Summary: -Wimplicit-fallthrough: cpp directive renders FALLTHRU
comment ineffective
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: jim at meyering dot net
Target Milestone: ---
Normally, adding a comment like /* FALLTHRU */ works fine to mark a switch case
that is intended to fall through. But if a cpp directive appears in the
vicinity of that comment, the comment becomes ineffective and we get the
warning anyway.
Here is a minimal example (without the "#undef", that comment *does* suppress
the warning):
int
foo (int x)
{
switch (x)
{
case 1:
x = 3;
#undef X
/* fallthrough */
case 2:
x = 4;
}
return x;
}
$ gcc -c -O -Wimplicit-fallthrough /t/ft.c
/t/ft.c: In function ‘foo’:
/t/ft.c:20:9: warning: this statement may fall through [-Wimplicit-fallthrough]
x = 3;
~~^~~
/t/ft.c:23:5: note: here
case 2:
^~~~
The above was compiled with yesterday's GCC 7:
gcc version 7.0.0 20161001 (experimental) (GCC)
I encountered an actual instance of this in gnulib's vasnprintf.c:
http://git.savannah.gnu.org/cgit/gnulib.git/tree/lib/vasnprintf.c#n4823