diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2019-07-31 21:50:04 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2019-07-31 21:50:04 +0000 |
commit | 6b58e2b5252e7b5c5aa760222b451d3f28587885 (patch) | |
tree | d5d4876c99b5903504c6a99de2c5b87167c12777 | |
parent | 285cf766c1309edd7e61bf0dc45754af987d1b26 (diff) | |
download | gcc-6b58e2b5252e7b5c5aa760222b451d3f28587885.zip gcc-6b58e2b5252e7b5c5aa760222b451d3f28587885.tar.gz gcc-6b58e2b5252e7b5c5aa760222b451d3f28587885.tar.bz2 |
decl2.c (delete_sanity): Improve diagnostic locations, use cp_expr_loc_or_loc in four places.
/cp
2019-07-31 Paolo Carlini <paolo.carlini@oracle.com>
* decl2.c (delete_sanity): Improve diagnostic locations, use
cp_expr_loc_or_loc in four places.
/testsuite
2019-07-31 Paolo Carlini <paolo.carlini@oracle.com>
* g++.dg/diagnostic/delete1.C: New.
From-SVN: r273952
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 23 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/diagnostic/delete1.C | 14 |
4 files changed, 39 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e30cc6d..f374636 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-07-31 Paolo Carlini <paolo.carlini@oracle.com> + + * decl2.c (delete_sanity): Improve diagnostic locations, use + cp_expr_loc_or_loc in four places. + 2019-07-31 Jason Merrill <jason@redhat.com> PR c++/90538 - multiple expansions of capture packs diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 3aba194..de67c7c 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -487,15 +487,19 @@ 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 (TREE_TYPE (exp)) == ARRAY_TYPE) - warning (0, "deleting array %q#E", exp); + if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE + && (complain & tf_warning)) + warning_at (cp_expr_loc_or_loc (exp, input_location), 0, + "deleting array %q#E", exp); t = build_expr_type_conversion (WANT_POINTER, exp, true); if (t == NULL_TREE || t == error_mark_node) { - error ("type %q#T argument given to %<delete%>, expected pointer", - TREE_TYPE (exp)); + if (complain & tf_error) + error_at (cp_expr_loc_or_loc (exp, input_location), + "type %q#T argument given to %<delete%>, expected pointer", + TREE_TYPE (exp)); return error_mark_node; } @@ -506,15 +510,20 @@ delete_sanity (tree exp, tree size, bool doing_vec, int use_global_delete, /* You can't delete functions. */ if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) { - error ("cannot delete a function. Only pointer-to-objects are " - "valid arguments to %<delete%>"); + if (complain & tf_error) + error_at (cp_expr_loc_or_loc (exp, input_location), + "cannot delete a function. Only pointer-to-objects are " + "valid arguments to %<delete%>"); return error_mark_node; } /* Deleting ptr to void is undefined behavior [expr.delete/3]. */ if (VOID_TYPE_P (TREE_TYPE (type))) { - warning (OPT_Wdelete_incomplete, "deleting %qT is undefined", type); + if (complain & tf_warning) + warning_at (cp_expr_loc_or_loc (exp, input_location), + OPT_Wdelete_incomplete, + "deleting %qT is undefined", type); doing_vec = 0; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 99f6b22..d878013 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-31 Paolo Carlini <paolo.carlini@oracle.com> + + * g++.dg/diagnostic/delete1.C: New. + 2019-07-31 Maxim Blinov <maxim.blinov@embecosm.com> * gcc.target/riscv/attribute-10.c: New test. diff --git a/gcc/testsuite/g++.dg/diagnostic/delete1.C b/gcc/testsuite/g++.dg/diagnostic/delete1.C new file mode 100644 index 0000000..d31458c --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/delete1.C @@ -0,0 +1,14 @@ +void f () +{ + int a[1]; + delete (a); // { dg-warning "11:deleting array" } + + bool b; + delete (b); // { dg-error "11:type .bool. argument" } + + void g (); + delete (g); // { dg-error "11:cannot delete a function" } + + void* p; + delete (p); // { dg-warning "11:deleting .void*." } +} |