class QByteArray { public: QByteArray(const QByteArray &); }; class QString { QByteArray toLocal8Bit() const __attribute__ ((warn_unused_result)); inline QByteArray local8Bit() const{ return toLocal8Bit(); } }; Produces with g++ -S -Wall: test.1.1.min.ii: In member function 'QByteArray QString::local8Bit() const': test.1.1.min.ii:7: warning: ignoring return value of 'QByteArray QString::toLocal8Bit() const', declared with attribute warn_unused_result
A regression from 3.4.6. Works in 4.1.0 - Janis, can you hunt this down?
Though 4.1.0 seems to not warn at all: class QByteArray { public: QByteArray(const QByteArray &); }; class QString { QByteArray toLocal8Bit() const __attribute__ ((warn_unused_result)); inline QByteArray local8Bit() const{ return toLocal8Bit(); } void fooWarnHere() const { toLocal8Bit(); } }; should warn for fooWarnHere, but doesn't.
The warning for the original testcase went away with this patch: r81764 | dnovillo | 2004-05-13 06:41:07 +0000 (Thu, 13 May 2004) | 3 lines Merge tree-ssa-20020619-branch into mainline. http://gcc.gnu.org/viewcvs?view=rev&rev=81764 Ouch! I've got another reghunt going to find out when the warning started being issued again between 4.0 and 4.1.
The warning was issued again with this patch: http://gcc.gnu.org/viewcvs?view=rev&rev=101269 r101269 | jason | 2005-06-23 14:44:21 +0000 (Thu, 23 Jun 2005)
The problem with 4.0 is that the CALL_EXPR uses the return slot address to return, but we don't honour that. Index: c-common.c =================================================================== *** c-common.c (revision 113528) --- c-common.c (working copy) *************** c_warn_unused_result (tree *top_p) *** 5658,5664 **** break; case CALL_EXPR: ! if (TREE_USED (t)) break; /* This is a naked call, as opposed to a CALL_EXPR nested inside --- 5658,5665 ---- break; case CALL_EXPR: ! if (TREE_USED (t) ! || CALL_EXPR_HAS_RETURN_SLOT_ADDR (t)) break; /* This is a naked call, as opposed to a CALL_EXPR nested inside though this makes PR27371 also fail for 4.0, as 4.0 shares the same problem of always emitting the "useless store".
Fixed in GCC-4.1.0