[patch] ld: optimize vfinfo output slightly

Ian Lance Taylor iant@google.com
Sat Mar 31 04:59:00 GMT 2012


Mike Frysinger <vapier@gentoo.org> writes:

> On Friday 30 March 2012 20:30:48 Alan Modra wrote:
>> On Fri, Mar 30, 2012 at 01:20:24PM -0400, Mike Frysinger wrote:
>> > the reason i didn't do that is it causes warnings since fwrite() is
>> > marked as "warn on unused result"
>> 
>> (void) fwrite (...);
>
> that doesn't work either
>
> $ cat test.c
> #include <stdio.h>
> main(){(void)fwrite("foo", 1, 1, stderr);}
> $ gcc -O2 -Wall test.c -c
> test.c:2:8: warning: ignoring return value of ‘fwrite’, declared with 
> attribute warn_unused_result [-Wunused-result]
>
> assigning it to a variable but not checking the variable no longer works with 
> newer gcc and -Wunused-but-set-parameter

The warn_unused_result attribute in gcc was designed for the realloc
function, where it is truly an error to ignore the result.  It is
absolutely not an error to ignore the result of fwrite; after all, it's
perfectly reasonable to use ferror.  It was a serious misunderstanding
for anybody to attach the warn_unused_result attribute to fwrite.  This
misunderstanding was made even more serious by somebody deciding that it
would be a good idea to have a compiler that defaults to defining
_FORTIFY_SOURCE.

So now we are in an absurd and painful situation, and there is no
consensus on how to get out of it.

Ian



More information about the Binutils mailing list