bug-coreutils
[Top][All Lists]
Advanced

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

bug#11829: Build failure with --enable-gcc-warnings


From: Eric Blake
Subject: bug#11829: Build failure with --enable-gcc-warnings
Date: Sat, 30 Jun 2012 17:53:51 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

On 06/30/2012 05:47 PM, Pádraig Brady wrote:

>>> +#ifdef CIBAUD
>>>    bool speed_was_set;
>>> +#else
>>> +  bool speed_was_set ATTRIBUTE_UNUSED;
>>> +#endif
>>
>> Three lines too many.  ATTRIBUTE_UNUSED is defined by gcc to mean 'might
>> be unused, therefore don't warn if it was not used', and not 'must not
>> be used, and therefore warn if it is used'.  Therefore, it is always
>> safe to use the one-liner:
>>
>> bool speed_was_set ATTRIBUTE_UNUSED;
>>
>> even if, when CIBAUD is defined, it was actually used.  No need for
>> extra #ifdef.
>>
> 
> But then you would never get such warnings for this variable.
> I was trying to disable the warning only where it's incorrect,
> and thought the single ifdef worth it?

My point is that there ARE no warnings if you unconditionally use the
label.  That is, gcc behaves the same with no warnings, on both the case
where CIBAUD is undefined and where it is defined, given either:

#ifdef CIBAUD
  bool speed_was_set;
#else
  bool speed_was_set ATTRIBUTE_UNUSED;
#endif
...
#ifdef CIBAUD
  use(speed_was_set);
#endif

or whether you use the shorter:

  bool speed_was_set ATTRIBUTE_UNUSED;
...
#ifdef CIBAUD
  use(speed_was_set);
#endif

and that's because the definition of ATTRIBUTE_UNUSED in gcc means only
"this _might_ be unused on some conditional compilations, so suppress
unused warnings".

Had gcc defined ATTRIBUTE_UNUSED as "warn if we used it after all", then
yes, you'd need the #ifdef.  Thankfully, gcc did not use that formulation.

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]