This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Implement -Wimplicit-fallthrough (version 9)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Tom Tromey <tom at tromey dot com>
- Cc: Michael Matz <matz at suse dot de>, Bernd Schmidt <bschmidt at redhat dot com>, Marek Polacek <polacek at redhat dot com>, Richard Biener <richard dot guenther at gmail dot com>, Eric Botcazou <ebotcazou at adacore dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Markus Trippelsdorf <markus at trippelsdorf dot de>, Jason Merrill <jason at redhat dot com>, Rainer Orth <ro at cebitec dot uni-bielefeld dot de>, Joseph Myers <joseph at codesourcery dot com>, Arnaud Charlet <charlet at adacore dot com>
- Date: Wed, 28 Sep 2016 21:10:48 +0200
- Subject: Re: Implement -Wimplicit-fallthrough (version 9)
- Authentication-results: sourceware.org; auth=none
- References: <a84b88e9-d6bd-31f4-a33e-1104531d7a22@redhat.com> <20160927115153.GU3223@redhat.com> <8521f44d-616c-a03d-879d-c400b13ce9d9@redhat.com> <20160927120108.GV3223@redhat.com> <6b5dbab6-0b5a-3f55-53e0-5dc419a3cd6a@redhat.com> <20160927134914.GW7282@tucnak.redhat.com> <alpine.LSU.2.20.1609271553120.5714@wotan.suse.de> <87ponpz56s.fsf@tromey.com> <alpine.LSU.2.20.1609281357210.5714@wotan.suse.de> <87wphwavr6.fsf@tromey.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Sep 28, 2016 at 09:29:01AM -0600, Tom Tromey wrote:
> >>>>> "Michael" == Michael Matz <matz@suse.de> writes:
>
> Michael> Not accepting
> Michael> /* And here we intentionally fall through because ... */
> Michael> and forcing users to replace this by:
> Michael> /* fallthrough */
> Michael> is not robust either. It's actually actively lowering robustness of code,
> Michael> it creates work for programmers that will be regarded as pointless (and
> Michael> rightly so) and will merely lead to everybody disabling the warning (see
> Michael> our generated files)
>
> We can't control what programmers might do. My point is that accepting
> too much is actively bad -- it hides errors. If this somehow makes some
> programmer fall down a slippery slope, well, that's their error, not
> gcc's.
>
> TBH I think it would be better not to parse comments at all. Heuristics
> are generally bad and this case and ensuing discussion is a great
> demonstration of that.
>
> The other day I built gdb with -Wimplicit-fallthrough. I was surprised
> to find that gcc rejected this:
>
> default:
> {
> complaint (&symfile_complaints,
> _("Storage class %d not recognized during scan"),
> sclass);
> }
> /* FALLTHROUGH */
>
> /* C_FCN is .bf and .ef symbols. I think it is sufficient
> to handle only the C_FUN and C_EXT. */
> case C_FCN:
>
> Presumably without the comment heuristic, this would be accepted.
Is complaint a noreturn call? If not, then it would certainly warn, unless
there is [[fallthrough]]; or __attribute__((fallthrough)); etc. (or the
comment). For the comment, /* FALLTHROUGH */ is the recognized spelling of
the comment, but right now we only look for such comments immediately before
a case/default keyword or user label; if there is another comment in
between, it is ignored. This is something we are considering to change,
exactly because often the /* FALLTHRU */ comment appears after some case and
then there is unrelated comment before the next case about what that case
handles.
Jakub