public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/44321]  New: attribute warn_unused_result fails under inlining.
@ 2010-05-29 11:33 davek at gcc dot gnu dot org
  2010-05-29 11:33 ` [Bug middle-end/44321] " davek at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: davek at gcc dot gnu dot org @ 2010-05-29 11:33 UTC (permalink / raw)
  To: gcc-bugs

In the (to-be) attached testcase, GCC warns about an unused result when the
return value of the function is ignored, or cast to void, but it fails to warn
when the cast-to-void is hidden inside an inline function, like so:

$ cat -n wur.c
     1
     2  static inline void ignore_value (int i) { (void) i; }
     3
     4  extern int foo (void) __attribute__ ((warn_unused_result));
     5
     6  void bar1 (void)
     7  {
     8    foo ();
     9  }
    10
    11  void bar2 (void)
    12  {
    13    (void) foo ();
    14  }
    15
    16  void bar3 (void)
    17  {
    18    ignore_value (foo ());
    19  }

$ gcc-4 -c wur.c  -o wur.o --save-temps -W -Wall -Wextra
wur.c: In function 'bar2':
wur.c:13:3: warning: ignoring return value of 'foo', declared with attribute
war
n_unused_result [-Wunused-result]
wur.c: In function 'bar1':
wur.c:8:7: warning: ignoring return value of 'foo', declared with attribute
warn
_unused_result [-Wunused-result]

This happens at all -O levels.  I haven't filled in the host/target/build
triplets because I don't suppose it is in any way specific to any of them.

BTW, it's interesting that the warnings come out in reverse order, is that
supposed to happen?


-- 
           Summary: attribute warn_unused_result fails under inlining.
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: davek at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-05-30  6:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-29 11:33 [Bug middle-end/44321] New: attribute warn_unused_result fails under inlining davek at gcc dot gnu dot org
2010-05-29 11:33 ` [Bug middle-end/44321] " davek at gcc dot gnu dot org
2010-05-29 11:40 ` rguenth at gcc dot gnu dot org
2010-05-29 17:32 ` bonzini at gnu dot org
2010-05-29 17:46 ` rguenth at gcc dot gnu dot org
2010-05-30  6:43 ` bonzini at gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).