This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Implement -Wswitch-fallthrough
- From: Marek Polacek <polacek at redhat dot com>
- To: NightStrike <nightstrike at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 13 Jul 2016 20:16:33 +0200
- Subject: Re: Implement -Wswitch-fallthrough
- Authentication-results: sourceware.org; auth=none
- References: <20160711194340.GI13963@redhat.com> <CAF1jjLtzJT2wMFJEZeX+r3vNT6sH=Sf-34yS+8UjPgXy7kntjQ@mail.gmail.com>
On Mon, Jul 11, 2016 at 04:28:32PM -0400, NightStrike wrote:
> On Mon, Jul 11, 2016 at 3:43 PM, Marek Polacek <polacek@redhat.com> wrote:
> > But then the [[fallthrough]] attribute was
> > approved for C++17 [1], and that's what has got me to do all this.
> > ...
> > I added a new builtin,
> > __builtin_fallthrough, that prevents the warning from occurring. It can only
> > be used in a switch; the compiler will issue an error otherwise. The new C++
> > attribute can then be implemented in terms of this builtin.
>
> This is a stupid question I'm sure, but if C++ can have the attribute
> version, why can't C have __attribute__((fallthrough)) ?
We could, but why? I already added __builtin_fallthrough() and
__attribute__((fallthrough)) would just be turned into that. C++17 adds the
fallthrough attribute for a null statement, so we need to implement that, but
again I expect that I just turn that to __builtin_fallthrough(). We plan to
add __Fallthrough to C, but that is a long way off. Does
"__attribute__((fallthrough));" have any advantages over "__builtin_fallthrough()"?
Marek