lkml.org 
[lkml]   [2019]   [Jul]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [RFC PATCH] compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use
From
Date
On Wed, 2019-07-31 at 19:14 +0200, Pavel Machek wrote:
> On Tue 2019-07-30 22:35:18, Joe Perches wrote:
> > Reserve the pseudo keyword 'fallthrough' for the ability to convert the
> > various case block /* fallthrough */ style comments to appear to be an
> > actual reserved word with the same gcc case block missing fallthrough
> > warning capability.
>
> Acked-by: Pavel Machek <pavel@ucw.cz>
>
> > +/*
> > + * Add the pseudo keyword 'fallthrough' so case statement blocks
> > + * must end with any of these keywords:
> > + * break;
> > + * fallthrough;
> > + * goto <label>;
> > + * return [expression];
> > + *
> > + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes
> > + */
> > +#if __has_attribute(__fallthrough__)
> > +# define fallthrough __attribute__((__fallthrough__))
> > +#else
> > +# define fallthrough do {} while (0) /* fallthrough */
> > +#endif
> > +
>
> Will various checkers (and gcc) recognize, that comment in a macro,
> and disable the warning accordingly?

Current non-gcc tools: I doubt it.

And that's unlikely as the comments are supposed to be stripped
before the macro expansion phase.

gcc 7+, which by now probably most developers actually use, will
though
and likely that's sufficient.

> Explanation that the comment is "magic" might not be a bad idea.

The comment was more for the reader.

cheers, Joe

\
 
 \ /
  Last update: 2019-07-31 19:52    [W:0.164 / U:0.192 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site