Paul Eggert wrote: > On 08/30/10 08:27, Eric Blake wrote: >> On 08/30/2010 08:29 AM, Bruce Korb wrote: >>> Every now and then, I'm thumped on the head by something fairly silly. >>> This warning is quite silly: >>> >>> (void)fwrite(...) >> >> Gnulib has the ignore-value module for places where casting to void is >> insufficient to shut up gcc. > > I share with Bruce Korb the dislike of casting to void, or using ignore_value. > I realize there is a benefit to catching some bugs, but there is also a cost > (a cost that can include causing more bugs), and in this case it's not at all > clear that the benefit exceeds the cost. > > In controversial areas like this, we should look to the GNU coding standards > for advice, and they state that one shouldn't cast to void, or use > similar measures merely to satisfy a lint checker. So I suggest that we > not use ignore-value; instead, we should avoid the GCC options that > generate these warnings. > > For gnulib, I suggest that we deprecate the ignore-value module.
Hi Paul, fwrite is an exception in that its value really is ignorable, if you know what you're doing. Hence, the warn_unused_result attribute on its declaration is the problem, not gcc, and not the ignore-value module. However, for the vast majority of the functions marked with this attribute, ignoring the return value really is a bug in all but a very small fraction of the use cases. The solution here could be to make gnulib provide a better declaration of fwrite: one without the offending attribute. Deprecating ignore-value or somehow disabling all warn_unused_result attributes would be overkill -- no reason to throw the baby out with the bathwater.