This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fwd: Fix an issue in unused value warning for C++ frontend (PR/39551)


Jason and Mark,

Here is the latest patch that fixes PR c++/39551. Please take a look.
(Hopefully 3rd time is a charm. :-)) Again, the patch was bootstrapped
and tested on x86_64-linux-gnu. Thanks.

Le-chun

2009-04-14  Le-Chun Wu  <lcwu@google.com>

        PR c++/39551
        * gcc/cp/call.c (build_over_call): Set TREE_NO_WARNING on the
        compiler-generated INDIRECT_REF expression.
        * gcc/cp/cvt.c (convert_to_void): Emit warning when stripping off
        INDIRECT_REF.
        * gcc/testsuite/g++.dg/warn/Wunused-13.C: New test.


Index: gcc/testsuite/g++.dg/warn/Wunused-13.C
===================================================================
--- gcc/testsuite/g++.dg/warn/Wunused-13.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/Wunused-13.C	(revision 0)
@@ -0,0 +1,7 @@
+// Test whether -Wunused handles effectless indirect_ref operation ('*').
+// { dg-do compile }
+// { dg-options "-Wunused" }
+
+void Foo(int* x) {
+  *x++; // { dg-warning "value computed is not used" }
+}
Index: gcc/cp/call.c
===================================================================
--- gcc/cp/call.c	(revision 146055)
+++ gcc/cp/call.c	(working copy)
@@ -5419,6 +5419,7 @@ build_over_call (struct z_candidate *can
 	  if (test)
 	    t = build3 (COND_EXPR, TREE_TYPE (t), test, arg0, t);
 	  val = cp_build_indirect_ref (t, 0, complain);
+          TREE_NO_WARNING (val) = 1;
 	}

       return val;
Index: gcc/cp/cvt.c
===================================================================
--- gcc/cp/cvt.c	(revision 146055)
+++ gcc/cp/cvt.c	(working copy)
@@ -870,7 +870,20 @@ convert_to_void (tree expr, const char *
                        implicit ? implicit : "void context");
           }
 	if (is_reference || !is_volatile || !is_complete || TREE_ADDRESSABLE (type))
-	  expr = TREE_OPERAND (expr, 0);
+          {
+            /* Emit a warning (if enabled) when the "effect-less" INDIRECT_REF
+               operation is stripped off. Note that we don't warn about
+               - an expression with TREE_NO_WARNING set. (For an example of
+                 such expressions, see build_over_call in call.c.)
+               - automatic dereferencing of references, since the user cannot
+                 control it. (See also warn_if_unused_value() in stmt.c.)  */
+            if (warn_unused_value
+                && (complain & tf_warning)
+                && !TREE_NO_WARNING (expr)
+                && !is_reference)
+              warning (OPT_Wunused_value, "value computed is not used");
+            expr = TREE_OPERAND (expr, 0);
+          }

 	break;
       }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]