This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/44321] New: attribute warn_unused_result fails under inlining.
- From: "davek at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 May 2010 11:32:55 -0000
- Subject: [Bug middle-end/44321] New: attribute warn_unused_result fails under inlining.
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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