Re: [PATCH 01/11] misc: fallthrough fixes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9 June 2017 at 22:10, Rüdiger Meier <sweet_f_a@xxxxxx> wrote:
>
>
> On 06/09/2017 01:14 PM, Ruediger Meier wrote:
>>
>> Hi,
>>
>> This patch looks a bit ugly, for example:
>>
>> ## gcc 4.8.1
>>
>>    CC       text-utils/more-more.o
>> ../text-utils/more.c: In function ‘command’:
>> ../text-utils/more.c:1273:4: warning: empty declaration [enabled by
>> default]
>>      UL_FALLTHROUGH;
>>
>> ## icc 16.0.0
>>
>> text-utils/more.c(1273): warning #1292: unknown attribute "fallthrough"
>>                          UL_FALLTHROUGH;
>>                          ^
>>
>>> diff --git a/include/c.h b/include/c.h
>>> index a5162b964..8a67b5dfb 100644
>>> --- a/include/c.h
>>> +++ b/include/c.h
>>> @@ -77,6 +77,24 @@
>>>   #endif
>>>     /*
>>> + * Statement Attributes
>>> + */
>>> +#if defined(__clang__)
>>> +# ifndef __has_cpp_attribute
>>> +#  define __has_cpp_attribute(x) 0
>>> +# endif
>>> +# if __has_cpp_attribute(clang::fallthrough)
>>> +#  define UL_FALLTHROUGH [[clang::fallthrough]]
>>> +# else
>>> +#  define UL_FALLTHROUGH /* fall through */
>>> +# endif
>>> +#elif defined(__GNUC__) || defined(__GNUG__)
>>> +# define UL_FALLTHROUGH __attribute__((fallthrough))
>>> +#else
>>> +# define UL_FALLTHROUGH /* FALLTHRU */
>>> +#endif
>>> +
>>> +/*
>
>
> Sorry this was broken. But I've checked now all clang and gcc versions.
> Looks
> like for clang the warning is only enabled when using C++ (clang++). So the
> fallthrough warning appears currently only on gcc>=7 and this works to
> disable
> it in a compatible way:
>
> #ifndef __has_cpp_attribute
> # define __has_cpp_attribute(x) 0
> #endif
>
> #if __has_cpp_attribute(fallthrough)
> # define UL_FALLTHROUGH __attribute__((fallthrough))
> #else
> # define UL_FALLTHROUGH /* fall through */
> #endif

Thank you for review Rudi. I had a look of the c.h again and did the
change a little bit differently:

#ifdef __has_cpp_attribute
# if __has_cpp_attribute(deprecated)
#  define UL_FALLTHROUGH __attribute__((fallthrough))
# elif __has_cpp_attribute(clang::fallthrough)
#  define UL_FALLTHROUGH [[clang::fallthrough]]
# endif
#endif
#ifndef UL_FALLTHROUGH
# define UL_FALLTHROUGH /* FALLTHRU */
#endif

The above is now part of my remote branch '2017wk23'.

-- 
Sami Kerola
http://www.iki.fi/kerolasa/
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux