GNU bug report logs - #11829
Build failure with --enable-gcc-warnings

Previous Next

Package: coreutils;

Reported by: Stefano Lattarini <stefano.lattarini <at> gmail.com>

Date: Sat, 30 Jun 2012 22:28:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eric Blake <eblake <at> redhat.com>
To: Pádraig Brady <P <at> draigBrady.com>
Cc: 11829 <at> debbugs.gnu.org
Subject: bug#11829: Build failure with --enable-gcc-warnings
Date: Sat, 30 Jun 2012 17:53:51 -0600
[Message part 1 (text/plain, inline)]
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   eblake <at> redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

This bug report was last modified 13 years and 22 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.