Bug 11224 - [3.4 regression] warning "value computed is not used" no longer emitted
Summary: [3.4 regression] warning "value computed is not used" no longer emitted
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.0.4
: P2 minor
Target Milestone: 4.0.0
Assignee: Mark Mitchell
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2003-06-17 17:56 UTC by Dirk Mueller
Modified: 2006-01-23 22:13 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 2.95.3 4.0.0 4.1.0
Known to fail: 3.4.0
Last reconfirmed: 2006-01-06 15:22:35


Attachments
testcase showing the problem. (119 bytes, text/plain)
2003-06-17 17:56 UTC, Dirk Mueller
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Mueller 2003-06-17 17:56:03 UTC
Hi,  
 
the attached testcase does no longer emit the "value computed is not 
used" warning. The regression was introduced somewhere between 2.95.4 and 
gcc 3.0.4, I'm currently trying to find the commit that broke it.  
 
I compile with g++ -Wall -W -O2 -c unused.cc 
 
expected output: 
 
unused.cc: In function `int main()': 
unused.cc:12: warning: value computed is not used 
 
actual output: <nothing>
Comment 1 Dirk Mueller 2003-06-17 17:56:55 UTC
Created attachment 4236 [details]
testcase showing the problem.
Comment 2 Andrew Pinski 2003-06-17 18:12:14 UTC
I can confirm this on the mainline (20030617), I think the problem is that isEmpty is not really 
being marked const so gcc says that there could be some side-effects which is clearly not true. 

from stmt.c:2430:
/* If this is an expression with side effects, don't warn.  */
      if (TREE_SIDE_EFFECTS (exp))
        return 0;
Comment 3 Dara Hazeghi 2003-06-17 18:26:41 UTC
Note that RedHat's patched 2.96 warns correctly while 3.0 does not.
Comment 4 Dirk Mueller 2003-06-18 18:26:34 UTC
adding __attribute__ ((pure)) or __attribute__ ((const)) makes no difference.  
 
however, its indeed caused by the HAS_SIDEEFFECTS check, as further checking 
has confirmed.  
Comment 5 Mark Mitchell 2003-06-27 21:45:39 UTC
This defect cannot easily be fixed.

The key problem is that TREE_SIDE_EFFECTS isn't the right test; the "x == foo()"
expression has side-effects, but that doesn't mean that the result of the
comparison is being used.

Distinguishing that case from "foo()" itself can't be done with
TREE_SIDE_EFFECTS; we need to look at the actual expression itself.

I've retargeted this PR for 3.4.
Comment 6 Nathan Sidwell 2003-09-06 19:39:36 UTC
add more smarts to convert_to_void so that it looks at the outermost tree code
to figure if that causes sideeffects
Comment 7 Andrew Pinski 2004-01-10 23:22:04 UTC
This is regression from 2.95.3 so moving to 3.4.1 and this should not block the branching.
Comment 8 Steven Bosscher 2004-01-12 23:39:42 UTC
Move back the target for all regressions from 3.4.1 to 3.4.0, as required by 
our bug management policy. 
Comment 9 Mark Mitchell 2004-02-20 09:09:35 UTC
Postponing until 3.5; any fix will be more dangerous than useful for 3.4.x.
Comment 10 Mark Mitchell 2004-12-22 04:57:26 UTC
Working on a fix.
Comment 11 GCC Commits 2004-12-22 18:01:00 UTC
Subject: Bug 11224

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-12-22 18:00:41

Modified files:
	gcc/testsuite  : ChangeLog 
	gcc/cp         : ChangeLog call.c cp-gimplify.c cvt.c rtti.c 
	                 typeck.c 
Added files:
	gcc/testsuite/g++.dg/template: cond5.C 
	gcc/testsuite/g++.dg/inherit: thunk3.C 
	gcc/testsuite/g++.dg/warn: Wunused-9.C 

Log message:
	PR c++/18464
	* call.c (build_this): In templates, do not bother with
	build_unary_op.
	* typeck.c (unary_complex_lvalue): In a template, always refuse
	simplifications.
	
	PR c++/18492
	* cp-gimplify.c (cp_genericize): Relax assertion.
	
	PR c++/11224
	* cvt.c (convert_to_void): Warn about unused values.
	
	PR c++/18257
	* rtti.c (emit_support_tinfos): On systems without weak symbols,
	emit the runtime library type-info objects as non-COMDAT.
	
	PR c++/18464
	* g++.dg/template/cond5.C: New test.
	
	PR c++/18492
	* g++.dg/inherit/thunk3.C: New test.
	
	PR c++/11224
	* g++.dg/warn/Wunused-9.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4799&r2=1.4800
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/cond5.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/inherit/thunk3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/Wunused-9.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4551&r2=1.4552
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&r1=1.524&r2=1.525
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-gimplify.c.diff?cvsroot=gcc&r1=1.16&r2=1.17
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cvt.c.diff?cvsroot=gcc&r1=1.174&r2=1.175
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/rtti.c.diff?cvsroot=gcc&r1=1.205&r2=1.206
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.605&r2=1.606

Comment 12 Mark Mitchell 2004-12-22 18:06:14 UTC
Fixed in G++ 4.0.
Comment 13 Jon Grimm 2005-01-10 19:01:12 UTC
FWIW, the xfail on Wunused-9.C :

...
  +f(); // { dg-warning "not used" "" { xfail *-*-* } }
...

is no longer failing, per: 

http://gcc.gnu.org/ml/gcc-testresults/2004-12/msg01344.html
http://gcc.gnu.org/ml/gcc-testresults/2004-12/msg01354.html

no longer an xfail?
Comment 14 Gabriel Dos Reis 2006-01-22 17:44:50 UTC
Fixed in 4.0.0 and higher.  Won't fix in 3.4.x
Comment 15 Andrew Pinski 2006-01-23 22:13:17 UTC
Fixed in 4.0.0 so closing as such.