Hi!

If base of delete[] has TREE_SIDE_EFFECTS, build_vec_delete
calls get_target_expr on it and we never call mark_exp_read on it in the
end.  Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk/4.8?

2013-09-09  Jakub Jelinek  <ja...@redhat.com>

        PR c++/58325
        * init.c (build_vec_delete): Call mark_rvalue_use on base.

        * g++.dg/warn/Wunused-var-21.C: New test.

--- gcc/cp/init.c.jj    2013-09-09 11:32:39.000000000 +0200
+++ gcc/cp/init.c       2013-09-09 12:33:23.244771455 +0200
@@ -4109,6 +4109,7 @@ build_vec_delete (tree base, tree maxind
       tree cookie_addr;
       tree size_ptr_type = build_pointer_type (sizetype);
 
+      base = mark_rvalue_use (base);
       if (TREE_SIDE_EFFECTS (base))
        {
          base_init = get_target_expr (base);
--- gcc/testsuite/g++.dg/warn/Wunused-var-21.C.jj       2013-09-09 
12:34:52.204318484 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-var-21.C  2013-09-09 12:34:36.000000000 
+0200
@@ -0,0 +1,31 @@
+// PR c++/58325
+// { dg-do compile }
+// { dg-options "-Wunused" }
+
+void
+f1 ()
+{
+  int *volatile a = new int[1];
+  delete[] a;
+}
+
+void
+f2 ()
+{
+  int *b = new int[1];
+  delete[] b;
+}
+
+void
+f3 ()
+{
+  int *volatile c = new int;
+  delete c;
+}
+
+void
+f4 ()
+{
+  int *d = new int;
+  delete d;
+}

        Jakub

Reply via email to