decl2.c (delete_sanity): Improve diagnostic locations, use cp_expr_loc_or_loc in...
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 31 Jul 2019 21:50:04 +0000 (21:50 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 31 Jul 2019 21:50:04 +0000 (21:50 +0000)
/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

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/delete1.C [new file with mode: 0644]

index e30cc6d8d771b0fa4aff49a665f3d48d45cd106c..f374636ed27427732f39216445246255b3a46683 100644 (file)
@@ -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
index 3aba194d824eb5a568f72984b5eb1a5d7086871e..de67c7c1cacedae5b399c3329a4d9c13e870a1f7 100644 (file)
@@ -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;
     }
 
index 99f6b22f86c1a9c62ee8ac5a17f8798ea7e5c85f..d878013c43225dc5f33cd4a78e6c53e2f69a2532 100644 (file)
@@ -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 (file)
index 0000000..d31458c
--- /dev/null
@@ -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*." }
+}