From: Paolo Carlini Date: Wed, 31 Jul 2019 21:50:04 +0000 (+0000) Subject: decl2.c (delete_sanity): Improve diagnostic locations, use cp_expr_loc_or_loc in... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6b58e2b5252e7b5c5aa760222b451d3f28587885;p=gcc.git decl2.c (delete_sanity): Improve diagnostic locations, use cp_expr_loc_or_loc in four places. /cp 2019-07-31 Paolo Carlini * decl2.c (delete_sanity): Improve diagnostic locations, use cp_expr_loc_or_loc in four places. /testsuite 2019-07-31 Paolo Carlini * g++.dg/diagnostic/delete1.C: New. From-SVN: r273952 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e30cc6d8d77..f374636ed27 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-07-31 Paolo Carlini + + * decl2.c (delete_sanity): Improve diagnostic locations, use + cp_expr_loc_or_loc in four places. + 2019-07-31 Jason Merrill PR c++/90538 - multiple expansions of capture packs diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 3aba194d824..de67c7c1cac 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 %, 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 %, 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 %"); + 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 %"); 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 99f6b22f86c..d878013c432 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-31 Paolo Carlini + + * g++.dg/diagnostic/delete1.C: New. + 2019-07-31 Maxim Blinov * 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 00000000000..d31458c726c --- /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*." } +}