This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Request for suppressing "warn_unused_result" warnings


Hi Paolo,

Can this design please be changed (or, dare I say without being considered impolite, improved) to better accommodate for the cases where there is indeed no reason for checking the return value?

Making the developers jump through more complicated ad hoc hoops (instead of just void-casting the func call) requires "too much" effort, and regular developers usually won't do it. So, this will increase the "warning noise", which will desensitize the developers, and make them pay less attention to really useful warnings. Cases like this therefore make the whole GCC warning mechanism less effective, and it diminishes the  great effort that you GCC developers put into helping developers write cleaner code.

Please make it simpler for the developers to write warning-free code!

Thanks,
Denis



-----Original Message-----
From: Paolo Bonzini [mailto:paolo.bonzini@gmail.com] On Behalf Of Paolo Bonzini
Sent: Friday, May 28, 2010 9:12 AM
To: Lavrentiev, Anton (NIH/NLM/NCBI) [C]
Cc: gcc@gcc.gnu.org; Vakatov, Denis (NIH/NLM/NCBI) [E]
Subject: Re: Request for suppressing "warn_unused_result" warnings

On 05/28/2010 06:36 AM, Lavrentiev, Anton (NIH/NLM/NCBI) [C] wrote:
> Dear GCC developers,
>
> Would you please consider suppressing (relatively new) warnings like
> this one:
>
> ignoring return value of 'int chdir(const char*)', declared with
> attribute warn_unused_result
>
> in cases when the source code explicitly casts the result to (void).
> Like in
>
> (void) chdir("/");
>
> There is no check necessary in this rare case, yet the compiler
> seems to ignore the explicit cast (which tells the developer's
> intention exactly: there is nothing to check), and keeps issuing the
> warning, regardless.
>
> Making dummy assignment and/or check around such a chdir call (just
> to satisfy the "unused result" requirement) will not help make the
> code any cleaner.
>
> There are always a subtle number of cases for almost any "__wur"
> call that do not need any result consumption.  Yet the warning in
> general is very helpful in catching the situation where the result is
> not consumed *explicitly*.
>
> We're lagging behind the GCC development here and perhaps the newest
> version of the compiler does already implement this suggestion -- so
> let me apologize for the noise then.
>
> Thanks for considering this suggestion,

Bugzilla unfortunately has a lot of discussion about this issue, and the
outcome was that the feature was done this way by design.

What you reported is not the only common intended violation of __wur.
It is for example possible to ignore the result of fwrite and defer
error checking to fflush or fclose, but __wur does not help with this
style.

I suggest that you add two functions like these:

static inline void ignore_value (int i) { (void) i; }
static inline void ignore_ptr (void* p) { (void) p; }

that you can use instead of the (void) cast.

Nevertheless, thanks for writing your report in a very polite way, which
didn't occur in some of the previous cases.

Paolo


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]