Bug 27370 - [4.0 Regression] Bogus warning about ignoring function return value (__attribute__ ((warn_unused_result)))
Summary: [4.0 Regression] Bogus warning about ignoring function return value (__attrib...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.3
: P3 minor
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2006-05-01 15:18 UTC by Richard Biener
Modified: 2007-02-03 16:54 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.6 4.1.0 4.2.0
Known to fail: 4.0.3
Last reconfirmed:


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:18:19 UTC
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
Comment 1 Richard Biener 2006-05-01 15:19:56 UTC
A regression from 3.4.6.  Works in 4.1.0 - Janis, can you hunt this down?
Comment 2 Richard Biener 2006-05-01 15:24:43 UTC
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.
Comment 3 Janis Johnson 2006-05-02 00:09:33 UTC
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.
Comment 4 Janis Johnson 2006-05-02 16:14:43 UTC
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)
Comment 5 Richard Biener 2006-05-04 15:25:36 UTC
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".
Comment 6 Gabriel Dos Reis 2007-02-03 16:54:10 UTC
Fixed in GCC-4.1.0