Bug 27371 - [4.1 Regression] Does not warn about unused function result (__attribute__((warn_unused_result)))
Summary: [4.1 Regression] Does not warn about unused function result (__attribute__((w...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.2.0
Assignee: Jason Merrill
URL:
Keywords: diagnostic
Depends on: 19317
Blocks:
  Show dependency treegraph
 
Reported: 2006-05-01 15:41 UTC by Richard Biener
Modified: 2006-09-08 07:40 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.0.3 4.2.0
Known to fail: 4.1.1
Last reconfirmed: 2006-09-06 05:49:06


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2006-05-01 15:41:31 UTC
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.
Comment 1 Richard Biener 2006-05-04 14:47:45 UTC
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.
Comment 2 Mark Mitchell 2006-05-25 02:34:42 UTC
Will not be fixed in 4.1.1; adjust target milestone to 4.1.2.
Comment 3 Jason Merrill 2006-09-06 05:59:39 UTC
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.
Comment 4 Jason Merrill 2006-09-06 18:47:38 UTC
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.
Comment 5 Jason Merrill 2006-09-07 01:13:06 UTC
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

Comment 6 H.J. Lu 2006-09-07 21:10:17 UTC
FWIW, g++.dg/warn/unused-result1.C fails:

http://gcc.gnu.org/ml/gcc-testresults/2006-09/msg00338.html
Comment 7 Jason Merrill 2006-09-07 22:47:42 UTC
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

Comment 8 Jason Merrill 2006-09-07 22:50:56 UTC
Subject: Re:  [4.1 Regression] Does not warn about unused function
 result (__attribute__((warn_unused_result)))

Whoops, I checked the patch in disabled.  Fixed.
Comment 9 Jason Merrill 2006-09-07 23:07:06 UTC
I don't think this patch is safe enough to backport to 4.1.  Closing.
Comment 10 Richard Biener 2006-09-08 07:40:27 UTC
Only fixed on the mainline.