From 0a9696f0225d1ab4a8d3a992c9e98f68e9996876 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 23 May 2012 14:19:27 +0000 Subject: [PATCH] re PR c++/29185 (inconsistent warning: deleting array) /cp 2012-05-23 Paolo Carlini PR c++/29185 * decl2.c (delete_sanity): Extend 'deleting array' warning to any array type. /testsuite 2012-05-23 Paolo Carlini PR c++/29185 * g++.dg/warn/delete-array-1.C: New. From-SVN: r187801 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl2.c | 5 ++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/warn/delete-array-1.C | 11 +++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/delete-array-1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 391407fb9da..c3d98418316 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2012-05-23 Paolo Carlini + + PR c++/29185 + * decl2.c (delete_sanity): Extend 'deleting array' warning to + any array type. + 2012-05-21 Paolo Carlini PR c++/51184 diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index c40b830a1aa..bf9ca333b35 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -438,9 +438,8 @@ delete_sanity (tree exp, tree size, bool doing_vec, int use_global_delete, } /* 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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4934bd2e4fe..35dd366c5e6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-05-23 Paolo Carlini + + PR c++/29185 + * g++.dg/warn/delete-array-1.C: New. + 2012-05-23 Richard Guenther * gcc.dg/torture/pr39074-2.c: Adjust. diff --git a/gcc/testsuite/g++.dg/warn/delete-array-1.C b/gcc/testsuite/g++.dg/warn/delete-array-1.C new file mode 100644 index 00000000000..c3af71323ac --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/delete-array-1.C @@ -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" } +}