Bug 34212 - spurious warning: value computed is not used
Summary: spurious warning: value computed is not used
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2007-11-24 02:16 UTC by Pawel Sikora
Modified: 2012-03-16 13:38 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.0.0 4.0.4 4.1.2 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0
Last reconfirmed: 2008-03-13 05:30:28


Attachments
Test case (230 bytes, text/plain)
2012-03-16 13:38 UTC, Jonathan Liu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pawel Sikora 2007-11-24 02:16:44 UTC
long f( long& );
template < typename T, bool B >
struct X
{
        X() : r_()
        {
                B ? f( r_ ) : ++r_;
        }
        long r_;
};
X< int, false > h;


$ /opt/gcc43/bin/g++ t.cpp -Wall -c
t.cpp: In constructor 'X<T, B>::X() [with T = int, bool B = false]':
t.cpp:11:   instantiated from here
t.cpp:7: warning: value computed is not used

this bug may be related to PR26632.
Comment 1 Pawel Sikora 2007-11-24 02:30:01 UTC
the warning isn't emitted when i change ++r_ into r_++.
t.cpp.003t.original changes:

-  (void) NON_LVALUE_EXPR < ++((struct X<int,false> *) this)->r_> >>>
+  (void) ((struct X<int,false> *) this)->r_++  >>>
Comment 2 Andrew Pinski 2007-11-24 12:15:51 UTC
A quick untested patch which I have not even tested on this testcase:
Index: stmt.c
===================================================================
--- stmt.c      (revision 130381)
+++ stmt.c      (working copy)
@@ -1408,6 +1408,9 @@ warn_if_unused_value (const_tree exp, lo
   if (EXPR_HAS_LOCATION (exp))
     locus = EXPR_LOCATION (exp);
 
+  while (TREE_CODE (exp) == NON_LVALUE_EXPR)
+    exp = TREE_OPERAND (exp, 0);
+
   switch (TREE_CODE (exp))
     {
     case PREINCREMENT_EXPR:
Comment 3 Pawel Sikora 2007-11-24 18:50:08 UTC
(In reply to comment #2)
> A quick untested patch which I have not even tested on this testcase:

doesn't work.
Comment 4 Andrew Pinski 2007-11-25 03:10:52 UTC
Confirmed, and here is a patch which really fixes the issue:
Index: ../../gcc/cp/cvt.c
===================================================================
--- ../../gcc/cp/cvt.c  (revision 130402)
+++ ../../gcc/cp/cvt.c  (working copy)
@@ -941,7 +941,8 @@ convert_to_void (tree expr, const char *
                 conversions.  Do not use STRIP_NOPs because it will
                 not strip conversions to "void", as that is not a
                 mode-preserving conversion.  */
-             while (TREE_CODE (e) == NOP_EXPR)
+             while (TREE_CODE (e) == NOP_EXPR
+                    || TREE_CODE (e) == NON_LVALUE_EXPR)
                e = TREE_OPERAND (e, 0);
 
              code = TREE_CODE (e);
Comment 5 Andrew Pinski 2007-12-03 03:17:54 UTC
Mine, but this will not get in until around the 25th.
Comment 6 Pawel Sikora 2008-01-08 19:00:48 UTC
(In reply to comment #5)
> Mine, but this will not get in until around the 25th.
> 

ping ;)
Comment 7 Pawel Sikora 2008-02-23 20:33:07 UTC
ping^2
Comment 8 Andrew Pinski 2008-02-23 20:35:01 UTC
(In reply to comment #7)
> ping^2

I am just finally getting back to my assigned bugs after so long, this is lower down on the list than some other ones.
Comment 9 Andrew Pinski 2008-03-12 03:48:31 UTC
I should be able to submit this patch tomorrow morning after the testing finishes.
Comment 10 Andrew Pinski 2008-03-13 05:27:59 UTC
+FAIL: g++.dg/warn/Wunused-9.C  (test for warnings, line 32)

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

+FAIL: g++.dg/warn/noeffect4.C  (test for warnings, line 80)

  const_cast<X &> (x.Foo ());       // { dg-warning "not used" }

I think the second one should not be warned about, but the first one I don't know about.  I am going to unassign this from me because of these regressions.
Comment 11 Andrew Pinski 2008-03-13 05:30:28 UTC
Actually I was looking at the wrong testresults :).  The build failed but I think that was my machine acting up again.
Comment 12 Andrew Pinski 2008-03-24 09:09:54 UTC
My patch does not work as we now don't warn for +f(); which is wrong.  I am no longer going to work on this.
Comment 13 Pawel Sikora 2010-05-05 19:35:03 UTC
queue.push_back with low prio ;)
Comment 14 Jonathan Liu 2012-03-16 13:38:18 UTC
Created attachment 26903 [details]
Test case

This test case gives a spurious 'warning: value computed is not used [-Wunused-value]' message when compiled with -Wall.