[Bug c/35579] __attribute__(( warn_unused_result )) warns when it shouldn't, doesn't warn when it should

pgut001 at cs dot auckland dot ac dot nz gcc-bugzilla@gcc.gnu.org
Fri Mar 14 06:56:00 GMT 2008



------- Comment #2 from pgut001 at cs dot auckland dot ac dot nz  2008-03-14 06:55 -------
>This is the design of warn_unused_result, you cannot ignore the value, 
>that is why casting to void does not work.

Doesn't this violate a C convention going back to the 1970s?  I did a fairly
long web/newsgroup search before filing this bug report and the advice given
was always to use the void cast, a practice going back to (at least) lint in
the late 1970s to get rid of its "function returns value which is always
ignored" warning, so the expectation from users seems to be that a void cast
will resolve this.

>The warning happens in the front-end so we don't know if you really ignore the
>value if you don't use the actually variable.

Is there any way of fixing this?  warn_unused_result is used in a number of
quite significant pieces of code to enforce safety properties (the Linux kernel
  springs to mind), having a compiler-enforced safety check that doesn't work
reliably seems rather dangerous.  If it can't be fixed then could it at least
be documented that the check isn't always reliable?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35579



More information about the Gcc-bugs mailing list