class QByteArray { public: QByteArray(const QByteArray &); }; class QString { QByteArray toLocal8Bit() const __attribute__ ((warn_unused_result)); void fooWarnHere() const { toLocal8Bit(); } }; Does not complain about fooWarnHere(). 4.0.3 did this.
Confirmed. The problem is that the C++ frontend emits unused_tmp = toLocal8Bit(); for the call. At least it has DECL_IGNORED set, so maybe I have a patch for this.
Will not be fixed in 4.1.1; adjust target milestone to 4.1.2.
This worked in 4.0 by accident, because of the NRV implementation I had in that release which pushed aggregate return values into the argument list of a call. This had some problems, so I later changed it to use a MODIFY_EXPR, which properly expresses what's going on, but interferes with this warning.
This is also complicated by PR 16269; we don't manage the lifetime of temporaries, so we don't know whether an initialized temporary is used again.
Subject: Bug 27371 Author: jason Date: Thu Sep 7 01:12:00 2006 New Revision: 116737 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116737 Log: PR c++/27371 * tree-inline.c (copy_result_decl_to_var): New fn. (declare_return_variable): Use it. Call declare_inline_vars here. (expand_call_inline): Not here. * cp/cvt.c (convert_to_void): Strip useless TARGET_EXPR. * cp/cp-tree.h (TARGET_EXPR_IMPLICIT_P): New macro. * cp/tree.c (build_cplus_new): Set it. Added: trunk/gcc/testsuite/g++.dg/warn/unused-result1.C Modified: trunk/gcc/ChangeLog trunk/gcc/cp/ChangeLog trunk/gcc/cp/cp-tree.h trunk/gcc/cp/cvt.c trunk/gcc/cp/tree.c trunk/gcc/tree-inline.c
FWIW, g++.dg/warn/unused-result1.C fails: http://gcc.gnu.org/ml/gcc-testresults/2006-09/msg00338.html
Subject: Bug 27371 Author: jason Date: Thu Sep 7 22:47:34 2006 New Revision: 116765 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116765 Log: PR c++/27371 * cvt.c (convert_to_void): Enable previous change. Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/cvt.c
Subject: Re: [4.1 Regression] Does not warn about unused function result (__attribute__((warn_unused_result))) Whoops, I checked the patch in disabled. Fixed.
I don't think this patch is safe enough to backport to 4.1. Closing.
Only fixed on the mainline.