Re: [RFC PATCH] compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use

From: Miguel Ojeda
Date: Sun Aug 04 2019 - 15:39:17 EST


On Sun, Aug 4, 2019 at 8:09 PM Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> So my only real concern is that the comment approach has always been
> the really traditional one, going back all the way to 'lint' days.
>
> And you obviously cannot use a #define to create a comment, so this
> whole keyword model will never be able to do that.
>
> At the same time, all the modern tools we care about do seem to be
> happy with it, either through the gcc attribute, the clang
> [[clang:fallthrough]] or the (eventual) standard C [[fallthrough]]
> model.

Quick note regarding C2x: fallthrough didn't make it yet into the
draft (other attributes already did), but it may still be added.

> So I'm ok with just saying "the comment model may be traditional, but
> it's not very good".
>
> I didn't look at all the patches, but the one I *did* see had a few issues:
>
> - it didn't seem to handle clang

Hmm... Not sure what this refers to, but note that Clang will likely
get support in the next release (they are working on it at the
moment). As far as I understand, we do not yet establish a minimum
version for Clang since they still solving several issues, no?

> - we'd need to make -Wimplicit-fallthrough be dependent on the
> compiler actually supporting the attribute, not just on supporting the
> flag.

If the above is correct (i.e. if we do not care about a specific
version of Clang just yet), and since gcc got support for the warning
at the same time as the attribute (7.1), I think we don't need to do
special handing for the warning; but if someone knows about a case
where we do have an issue with it either with GCC or Clang, please let
me know.

> without those changes, nobody can actually start doing any
> conversions. But I assume such patches exist somewhere, and I've just
> missed them.

I think the primary concern has always been the tooling (e.g. Coverity
was mentioned in October and also this time, and well as some
IDEs/text editors), not the compilers themselves.

Cheers,
Miguel