This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix -Wunused-but-set-* with delete [] (PR c++/58325)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 9 Sep 2013 17:25:27 +0200
- Subject: [C++ PATCH] Fix -Wunused-but-set-* with delete [] (PR c++/58325)
- Authentication-results: sourceware.org; auth=none
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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 <jakub@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