This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/35579] __attribute__(( warn_unused_result )) warns when it shouldn't, doesn't warn when it should
- From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 Mar 2008 12:08:37 -0000
- Subject: [Bug c/35579] __attribute__(( warn_unused_result )) warns when it shouldn't, doesn't warn when it should
- References: <bug-35579-15916@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #4 from pinskia at gcc dot gnu dot org 2008-03-14 12:08 -------
(In reply to comment #3)
> (In reply to comment #2)
> > >This is the design of warn_unused_result, you cannot ignore the value,
> > >that is why casting to void does not work.
>
> I agree with the reporter. There should be a way to tell the compiler to avoid
> warning for particular cases. Casting to void seems to be the best way to do
> that.
http://gcc.gnu.org/ml/gcc/2006-11/msg00468.html
The original patch has a testcase explicitly checking for the case where cast
to void is there:
http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00875.html
+ (void) check1 (); /* { dg-warning "ignoring return value of" } */
As for the other stuff, the manual says:
+The @code{warn_unused_result} attribute causes a warning to be emitted
+if a caller of the function with this attribute does not use its
+return value. This is useful for functions where not checking
+the result is either a security problem or always a bug, such as
+@code{realloc}.
The return value is used, it is assigned to a variable, just that variable is
not used which is a different story.
I think we can declare this bug as invalid really.
-- Pinski
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35579