On 05/23/2012 06:34 AM, Jason Merrill wrote:
On 05/22/2012 09:25 PM, Paolo Carlini wrote:
some years ago Martin lamented that we weren't consistently warning
about deleting member arrays vs arrays.

I wonder why we look at the code of exp at all. Surely deleting any expression with array type is questionable.
Indeed. The below, as-is, bootstraps and tests fine.

I wondered whether adding a check that TREE_TYPE is non null could provide a tad of additional robustness, but noticed that the next build_expr_type_conversion just uses MAYBE_CLASS_TYPE_P on it.

Thanks!
Paolo.

/////////////////
Index: testsuite/g++.dg/warn/delete-array-1.C
===================================================================
--- testsuite/g++.dg/warn/delete-array-1.C      (revision 0)
+++ testsuite/g++.dg/warn/delete-array-1.C      (revision 0)
@@ -0,0 +1,11 @@
+// PR c++/29185
+
+int a [1];
+struct S { int a [1]; } s;
+
+void foo (S *p)
+{
+  delete a;    // { dg-warning "deleting array" }
+  delete s.a;  // { dg-warning "deleting array" }
+  delete p->a; // { dg-warning "deleting array" }
+}
Index: cp/decl2.c
===================================================================
--- cp/decl2.c  (revision 187799)
+++ cp/decl2.c  (working copy)
@@ -438,9 +438,8 @@ delete_sanity (tree exp, tree size, bool doing_vec
     }
 
   /* An array can't have been allocated by new, so complain.  */
-  if (TREE_CODE (exp) == VAR_DECL
-      && TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
-    warning (0, "deleting array %q#D", exp);
+  if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
+    warning (0, "deleting array %q#E", exp);
 
   t = build_expr_type_conversion (WANT_POINTER, exp, true);
 

Reply via email to