lkml.org 
[lkml]   [2019]   [Jul]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [RFC PATCH] compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use
From
On July 31, 2019 11:48:32 AM PDT, Peter Zijlstra <peterz@infradead.org> wrote:
>On Wed, Jul 31, 2019 at 11:24:36AM -0700, hpa@zytor.com wrote:
>> >> > +/*
>> >> > + * 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
>> >> > +
>
>> If the comments are stripped, how would the compiler see them to be
>> able to issue a warning? I would guess that it is retained or
>replaced
>> with some other magic token.
>
>Everything that has the warning (GCC-7+/CLANG-9) has that attribute.

The standard is moving toward adding this as an attribute with the [[fallthrough]] syntax; it is in C++17, not sure when it will be in C be if it isn't already.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

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