]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/39551 (C++ frontend not warn about unused dereference operator with -Wunuse...
authorLe-Chun Wu <lcwu@google.com>
Wed, 15 Apr 2009 17:55:50 +0000 (17:55 +0000)
committerLe-Chun Wu <lcwu@gcc.gnu.org>
Wed, 15 Apr 2009 17:55:50 +0000 (17:55 +0000)
        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 testcase.

From-SVN: r146132

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cvt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wunused-13.C [new file with mode: 0644]

index aa0ef54e603a60614e18ee2d37f32958a67935db..0cd3460e29136650f3e65e335ee0b7ac90b43075 100644 (file)
@@ -1,3 +1,11 @@
+2009-04-15  Le-Chun Wu  <lcwu@google.com>
+
+       PR c++/39551
+       * call.c (build_over_call): Set TREE_NO_WARNING on the
+       compiler-generated INDIRECT_REF expression.
+       * cvt.c (convert_to_void): Emit warning when stripping off
+       INDIRECT_REF.
+
 2009-04-14  Diego Novillo  <dnovillo@google.com>
 
        * parser.c (cp_parser_type_specifier_seq): Move call to
index ef7c045acab4af1629c4fbd27c16f4c457421a7b..f6c24b690863e7340f8586bb6bfbc41f7ea607c7 100644 (file)
@@ -5419,6 +5419,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
          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 fed4ab2910c4a570b779a9e70cc59a22e6f378b8..5032f1c039169488b6d4426554e00da34c769dfb 100644 (file)
@@ -870,7 +870,20 @@ convert_to_void (tree expr, const char *implicit, tsubst_flags_t complain)
                        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 ffcd8889eefcc8fc6ec70b762a2e284202244fe0..00964103e75653785821141ed78756042d77792a 100644 (file)
@@ -1,3 +1,8 @@
+2009-04-15  Le-Chun Wu  <lcwu@google.com>
+
+       PR c++/39551
+       * g++.dg/warn/Wunused-13.C: New testcase.
+
 2009-04-15  Ian Lance Taylor  <iant@google.com>
 
        * gcc.dg/Wenum-compare-1.c: New testcase.
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-13.C b/gcc/testsuite/g++.dg/warn/Wunused-13.C
new file mode 100644 (file)
index 0000000..d0eae11
--- /dev/null
@@ -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" }
+}