Hi,

some years ago Martin lamented that we weren't consistently warning about deleting member arrays vs arrays. A fix seems simple and passes bootstrap and testing on x86_64-linux. Note I have to change D to E because dump_decl cannot cope with COMPONENT_REFs.

Thanks,
Paolo.

//////////////////////
/cp
2012-05-23  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/29185
        * decl2.c (delete_sanity): Extend 'deleting array' warning to
        member arrays.

/testsuite
2012-05-23  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/29185
        * g++.dg/warn/delete-array-1.C: New.
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 187780)
+++ cp/decl2.c  (working copy)
@@ -438,9 +438,10 @@ 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
+  if ((TREE_CODE (exp) == VAR_DECL
+       || TREE_CODE (exp) == COMPONENT_REF)
       && TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
-    warning (0, "deleting array %q#D", exp);
+    warning (0, "deleting array %q#E", exp);
 
   t = build_expr_type_conversion (WANT_POINTER, exp, true);
 

Reply via email to