Bug 39808 - warn_unused_result fails to produce warning in a statement expression
Summary: warn_unused_result fails to produce warning in a statement expression
Status: ASSIGNED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Dave Pagan
URL:
Keywords: diagnostic, stmt-expr
Depends on:
Blocks:
 
Reported: 2009-04-18 17:31 UTC by Søren Sandmann Pedersen
Modified: 2022-11-28 18:36 UTC (History)
3 users (show)

See Also:
Host: i386-redhat-linux
Target: i386-redhat-linux
Build: i386-redhat-linux
Known to work:
Known to fail: 5.3.0, 6.3.0, 7.1.0, 8.0
Last reconfirmed: 2017-07-25 00:00:00


Attachments
program (112 bytes, text/plain)
2009-04-18 17:32 UTC, Søren Sandmann Pedersen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Søren Sandmann Pedersen 2009-04-18 17:31:40 UTC
The program to be attached produces the warning

[ssp@dhcp-100-2-40 ~]$ gcc gb.c
gb.c: In function ‘main’:
gb.c:11: warning: ignoring return value of ‘foo’, declared with attribute warn_unused_result

which is expected. However, it should also produce a warning for line 12, which is exactly the same except a dummy variable is declared.



Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-cpu=generic --build=i386-redhat-linux
Thread model: posix
gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC)
Comment 1 Søren Sandmann Pedersen 2009-04-18 17:32:54 UTC
Created attachment 17654 [details]
program
Comment 2 Andrew Pinski 2009-04-21 17:59:18 UTC
I think neither of these cases should be warned about since you are using it with a statement expression.
Comment 3 Søren Sandmann Pedersen 2009-04-22 17:03:52 UTC
Why not? If not using the return value is a bug, then it's also a bug if it isn't used after being passed through a statement expression.
Comment 4 Martin Sebor 2017-07-25 23:19:03 UTC
Confirmed.
Comment 5 Dave Pagan 2018-03-15 16:03:19 UTC
Anyone looking at this? If not, I'd like to.
Comment 6 Paolo Carlini 2018-03-26 17:50:25 UTC
Dave is on it.