diff mbox series

[C++] Improve delete_sanity locations

Message ID 5b89d4fe-88b7-b51b-fc0e-11833bde2c34@oracle.com
State New
Headers show
Series [C++] Improve delete_sanity locations | expand

Commit Message

Paolo Carlini July 24, 2019, 9:24 p.m. UTC
Hi,

this takes care of the four locations, two warnings and two errors. I'm 
also adding the missing complain & tf_warning or tf_error guards, I 
don't have a SFINAE testcase failing but since the function takes a 
tsubst_flags_t argument I think it's the right thing to do. Tested 
x86_64-linux.

By the way, shall we add to cp-tree.h, at least temporarily, a:

inline location_t
cp_expr_loc_or_loc (const_tree t)
{
   return cp_expr_loc_or_loc (t, input_location);
}

overload? We could use it in a ton of places.

Thanks, Paolo.

//////////////////////////
/cp
2019-07-24  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-24  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/diagnostic/delete1.C: New.

Comments

Jason Merrill July 31, 2019, 7:14 p.m. UTC | #1
On 7/24/19 5:24 PM, Paolo Carlini wrote:
> this takes care of the four locations, two warnings and two errors. I'm 
> also adding the missing complain & tf_warning or tf_error guards, I 
> don't have a SFINAE testcase failing but since the function takes a 
> tsubst_flags_t argument I think it's the right thing to do. Tested 
> x86_64-linux.

OK.

> By the way, shall we add to cp-tree.h, at least temporarily, a:
> 
> inline location_t
> cp_expr_loc_or_loc (const_tree t)
> {
>    return cp_expr_loc_or_loc (t, input_location);
> }
> 
> overload? We could use it in a ton of places.

I'd call it "cp_expr_loc_or_here".  But David removed EXPR_LOC_OR_HERE a 
few years back, so I'd like him to weigh in.

Jason
David Malcolm July 31, 2019, 7:39 p.m. UTC | #2
On Wed, 2019-07-31 at 15:14 -0400, Jason Merrill wrote:
> On 7/24/19 5:24 PM, Paolo Carlini wrote:
> > this takes care of the four locations, two warnings and two errors.
> > I'm 
> > also adding the missing complain & tf_warning or tf_error guards,
> > I 
> > don't have a SFINAE testcase failing but since the function takes
> > a 
> > tsubst_flags_t argument I think it's the right thing to do. Tested 
> > x86_64-linux.
> 
> OK.
> 
> > By the way, shall we add to cp-tree.h, at least temporarily, a:
> > 
> > inline location_t
> > cp_expr_loc_or_loc (const_tree t)
> > {
> >    return cp_expr_loc_or_loc (t, input_location);
> > }
> > 
> > overload? We could use it in a ton of places.
> 
> I'd call it "cp_expr_loc_or_here".  But David removed
> EXPR_LOC_OR_HERE a 
> few years back, so I'd like him to weigh in.

I don't care for "cp_expr_loc_or_loc".

By "_or_here" do you mean "or input_location"?

Calling it "cp_expr_loc_or_input_location" would spell out what it
does, but would be rather long.

Dave
Paolo Carlini Aug. 2, 2019, 12:02 p.m. UTC | #3
Hi,

On 31/07/19 21:39, David Malcolm wrote:

[snip]
> I don't care for "cp_expr_loc_or_loc".
>
> By "_or_here" do you mean "or input_location"?
>
> Calling it "cp_expr_loc_or_input_location" would spell out what it
> does, but would be rather long.

Thanks for your feedback. At this point I don't feel very strongly about 
the issue, and, well, hopefully it's just temporary material, but I 
tested the below which proposes the name cp_expr_loc_or_input_loc. Seems 
a good balance to me. What do you think?

Cheers, Paolo.

/////////////////
Index: call.c
===================================================================
--- call.c	(revision 274001)
+++ call.c	(working copy)
@@ -4184,7 +4184,7 @@ build_converted_constant_expr_internal (tree type,
   conversion *conv;
   void *p;
   tree t;
-  location_t loc = cp_expr_loc_or_loc (expr, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (expr);
 
   if (error_operand_p (expr))
     return error_mark_node;
@@ -6961,7 +6961,7 @@ convert_like_real (conversion *convs, tree expr, t
   tree totype = convs->type;
   diagnostic_t diag_kind;
   int flags;
-  location_t loc = cp_expr_loc_or_loc (expr, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (expr);
 
   if (convs->bad_p && !(complain & tf_error))
     return error_mark_node;
@@ -7481,7 +7481,7 @@ tree
 convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
 {
   tree arg_type;
-  location_t loc = cp_expr_loc_or_loc (arg, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (arg);
 
   /* [expr.call]
 
@@ -7789,7 +7789,7 @@ convert_for_arg_passing (tree type, tree val, tsub
 		     "argument of function call might be a candidate "
 		     "for a format attribute");
 	}
-      maybe_warn_parm_abi (type, cp_expr_loc_or_loc (val, input_location));
+      maybe_warn_parm_abi (type, cp_expr_loc_or_input_loc (val));
     }
 
   if (complain & tf_warning)
@@ -8595,7 +8595,7 @@ build_over_call (struct z_candidate *cand, int fla
       tree type = TREE_TYPE (to);
       tree as_base = CLASSTYPE_AS_BASE (type);
       tree arg = argarray[1];
-      location_t loc = cp_expr_loc_or_loc (arg, input_location);
+      location_t loc = cp_expr_loc_or_input_loc (arg);
 
       if (is_really_empty_class (type, /*ignore_vptr*/true))
 	{
@@ -9143,7 +9143,7 @@ build_cxx_call (tree fn, int nargs, tree *argarray
   tree fndecl;
 
   /* Remember roughly where this call is.  */
-  location_t loc = cp_expr_loc_or_loc (fn, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (fn);
   fn = build_call_a (fn, nargs, argarray);
   SET_EXPR_LOCATION (fn, loc);
 
@@ -11183,7 +11183,7 @@ perform_implicit_conversion_flags (tree type, tree
 {
   conversion *conv;
   void *p;
-  location_t loc = cp_expr_loc_or_loc (expr, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (expr);
 
   if (TYPE_REF_P (type))
     expr = mark_lvalue_use (expr);
@@ -11532,7 +11532,7 @@ initialize_reference (tree type, tree expr,
 {
   conversion *conv;
   void *p;
-  location_t loc = cp_expr_loc_or_loc (expr, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (expr);
 
   if (type == error_mark_node || error_operand_p (expr))
     return error_mark_node;
Index: constexpr.c
===================================================================
--- constexpr.c	(revision 274001)
+++ constexpr.c	(working copy)
@@ -1527,7 +1527,7 @@ cxx_eval_internal_function (const constexpr_ctx *c
 
     default:
       if (!ctx->quiet)
-	error_at (cp_expr_loc_or_loc (t, input_location),
+	error_at (cp_expr_loc_or_input_loc (t),
 		  "call to internal function %qE", t);
       *non_constant_p = true;
       return t;
@@ -1542,7 +1542,7 @@ cxx_eval_internal_function (const constexpr_ctx *c
 
   if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
     {
-      location_t loc = cp_expr_loc_or_loc (t, input_location);
+      location_t loc = cp_expr_loc_or_input_loc (t);
       tree type = TREE_TYPE (TREE_TYPE (t));
       tree result = fold_binary_loc (loc, opcode, type,
 				     fold_convert_loc (loc, type, arg0),
@@ -1584,7 +1584,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx
 			  bool lval,
 			  bool *non_constant_p, bool *overflow_p)
 {
-  location_t loc = cp_expr_loc_or_loc (t, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (t);
   tree fun = get_function_named_in_call (t);
   constexpr_call new_call
     = { NULL, NULL, NULL, 0, ctx->manifestly_const_eval };
@@ -2580,7 +2580,7 @@ eval_and_check_array_index (const constexpr_ctx *c
 			    tree t, bool allow_one_past,
 			    bool *non_constant_p, bool *overflow_p)
 {
-  location_t loc = cp_expr_loc_or_loc (t, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (t);
   tree ary = TREE_OPERAND (t, 0);
   t = TREE_OPERAND (t, 1);
   tree index = cxx_eval_constant_expression (ctx, t, false,
@@ -3909,7 +3909,7 @@ cxx_eval_store_expression (const constexpr_ctx *ct
 	      if (cxx_dialect < cxx2a)
 		{
 		  if (!ctx->quiet)
-		    error_at (cp_expr_loc_or_loc (t, input_location),
+		    error_at (cp_expr_loc_or_input_loc (t),
 			      "change of the active member of a union "
 			      "from %qD to %qD",
 			      CONSTRUCTOR_ELT (*valp, 0)->index,
@@ -4220,7 +4220,7 @@ cxx_eval_statement_list (const constexpr_ctx *ctx,
       /* We aren't communicating the jump to our caller, so give up.  We don't
 	 need to support evaluation of jumps out of statement-exprs.  */
       if (!ctx->quiet)
-	error_at (cp_expr_loc_or_loc (r, input_location),
+	error_at (cp_expr_loc_or_input_loc (r),
 		  "statement is not a constant expression");
       *non_constant_p = true;
     }
@@ -4320,7 +4320,7 @@ cxx_eval_loop_expr (const constexpr_ctx *ctx, tree
       if (++count >= constexpr_loop_limit)
 	{
 	  if (!ctx->quiet)
-	    error_at (cp_expr_loc_or_loc (t, input_location),
+	    error_at (cp_expr_loc_or_input_loc (t),
 		      "%<constexpr%> loop iteration count exceeds limit of %d "
 		      "(use %<-fconstexpr-loop-limit=%> to increase the limit)",
 		      constexpr_loop_limit);
@@ -4482,7 +4482,7 @@ cxx_eval_constant_expression (const constexpr_ctx
   if (++*ctx->constexpr_ops_count >= constexpr_ops_limit)
     {
       if (!ctx->quiet)
-	error_at (cp_expr_loc_or_loc (t, input_location),
+	error_at (cp_expr_loc_or_input_loc (t),
 		  "%<constexpr%> evaluation operation count exceeds limit of "
 		  "%wd (use %<-fconstexpr-ops-limit=%> to increase the limit)",
 		  constexpr_ops_limit);
@@ -5036,7 +5036,7 @@ cxx_eval_constant_expression (const constexpr_ctx
       if (REINTERPRET_CAST_P (t))
 	{
 	  if (!ctx->quiet)
-	    error_at (cp_expr_loc_or_loc (t, input_location),
+	    error_at (cp_expr_loc_or_input_loc (t),
 		      "%<reinterpret_cast%> is not a constant expression");
 	  *non_constant_p = true;
 	  return t;
@@ -5077,7 +5077,7 @@ cxx_eval_constant_expression (const constexpr_ctx
 		if (TYPE_REF_P (type))
 		  {
 		    if (!ctx->quiet)
-		      error_at (cp_expr_loc_or_loc (t, input_location),
+		      error_at (cp_expr_loc_or_input_loc (t),
 				"dereferencing a null pointer");
 		    *non_constant_p = true;
 		    return t;
@@ -5089,7 +5089,7 @@ cxx_eval_constant_expression (const constexpr_ctx
 		    if (!can_convert (type, from, tf_none))
 		      {
 			if (!ctx->quiet)
-			  error_at (cp_expr_loc_or_loc (t, input_location),
+			  error_at (cp_expr_loc_or_input_loc (t),
 				    "conversion of %qT null pointer to %qT "
 				    "is not a constant expression",
 				    from, type);
@@ -5104,7 +5104,7 @@ cxx_eval_constant_expression (const constexpr_ctx
 		     reinterpret_cast<void*>(sizeof 0)
 		*/
 		if (!ctx->quiet)
-		  error_at (cp_expr_loc_or_loc (t, input_location),
+		  error_at (cp_expr_loc_or_input_loc (t),
 			    "%<reinterpret_cast<%T>(%E)%> is not "
 			    "a constant expression",
 			    type, op);
@@ -5178,7 +5178,7 @@ cxx_eval_constant_expression (const constexpr_ctx
     case BASELINK:
     case OFFSET_REF:
       if (!ctx->quiet)
-        error_at (cp_expr_loc_or_loc (t, input_location),
+        error_at (cp_expr_loc_or_input_loc (t),
 		  "expression %qE is not a constant expression", t);
       *non_constant_p = true;
       break;
@@ -5196,7 +5196,7 @@ cxx_eval_constant_expression (const constexpr_ctx
 	    || !DECL_P (get_base_address (TREE_OPERAND (obj, 0))))
 	  {
 	    if (!ctx->quiet)
-	      error_at (cp_expr_loc_or_loc (t, input_location),
+	      error_at (cp_expr_loc_or_input_loc (t),
 			"expression %qE is not a constant expression", t);
 	    *non_constant_p = true;
 	    return t;
@@ -5960,7 +5960,7 @@ potential_constant_expression_1 (tree t, bool want
     return false;
   if (t == NULL_TREE)
     return true;
-  location_t loc = cp_expr_loc_or_loc (t, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (t);
 
   if (*jump_target)
     /* If we are jumping, ignore everything.  This is simpler than the
Index: constraint.cc
===================================================================
--- constraint.cc	(revision 274001)
+++ constraint.cc	(working copy)
@@ -805,7 +805,7 @@ check_for_logical_overloads (tree t)
 
   if (DECL_OVERLOADED_OPERATOR_P (fn))
     {
-      location_t loc = cp_expr_loc_or_loc (t, input_location);
+      location_t loc = cp_expr_loc_or_input_loc (t);
       error_at (loc, "constraint %qE, uses overloaded operator", t);
       return true;
     }
@@ -2016,7 +2016,7 @@ satisfy_predicate_constraint (tree t, tree args,
   tree type = cv_unqualified (TREE_TYPE (expr));
   if (!same_type_p (type, boolean_type_node))
     {
-      error_at (cp_expr_loc_or_loc (expr, input_location),
+      error_at (cp_expr_loc_or_input_loc (expr),
                 "constraint %qE does not have type %qT",
                 expr, boolean_type_node);
       return boolean_false_node;
Index: cp-gimplify.c
===================================================================
--- cp-gimplify.c	(revision 274001)
+++ cp-gimplify.c	(working copy)
@@ -644,7 +644,7 @@ int
 cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
 {
   int saved_stmts_are_full_exprs_p = 0;
-  location_t loc = cp_expr_loc_or_loc (*expr_p, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (*expr_p);
   enum tree_code code = TREE_CODE (*expr_p);
   enum gimplify_status ret;
 
Index: cp-tree.h
===================================================================
--- cp-tree.h	(revision 274001)
+++ cp-tree.h	(working copy)
@@ -7509,11 +7509,17 @@ cp_expr_loc_or_loc (const_tree t, location_t or_lo
   return loc;
 }
 
+inline location_t
+cp_expr_loc_or_input_loc (const_tree t)
+{
+  return cp_expr_loc_or_loc (t, input_location);
+}
+
 inline void
 cxx_incomplete_type_diagnostic (const_tree value, const_tree type,
 				diagnostic_t diag_kind)
 {
-  cxx_incomplete_type_diagnostic (cp_expr_loc_or_loc (value, input_location),
+  cxx_incomplete_type_diagnostic (cp_expr_loc_or_input_loc (value),
 				  value, type, diag_kind);
 }
 
Index: cvt.c
===================================================================
--- cvt.c	(revision 274001)
+++ cvt.c	(working copy)
@@ -77,7 +77,7 @@ cp_convert_to_pointer (tree type, tree expr, bool
   tree intype = TREE_TYPE (expr);
   enum tree_code form;
   tree rval;
-  location_t loc = cp_expr_loc_or_loc (expr, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (expr);
 
   if (intype == error_mark_node)
     return error_mark_node;
@@ -419,7 +419,7 @@ convert_to_reference (tree reftype, tree expr, int
   tree rval = NULL_TREE;
   tree rval_as_conversion = NULL_TREE;
   bool can_convert_intype_to_type;
-  location_t loc = cp_expr_loc_or_loc (expr, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (expr);
 
   if (TREE_CODE (type) == FUNCTION_TYPE
       && TREE_TYPE (expr) == unknown_type_node)
@@ -671,7 +671,7 @@ cp_convert_and_check (tree type, tree expr, tsubst
       folded_result = fold_simple (folded_result);
       if (!TREE_OVERFLOW_P (folded)
 	  && folded_result != error_mark_node)
-	warnings_for_convert_and_check (cp_expr_loc_or_loc (expr, input_location),
+	warnings_for_convert_and_check (cp_expr_loc_or_input_loc (expr),
 					type, folded, folded_result);
     }
 
@@ -690,7 +690,7 @@ ocp_convert (tree type, tree expr, int convtype, i
   enum tree_code code = TREE_CODE (type);
   const char *invalid_conv_diag;
   tree e1;
-  location_t loc = cp_expr_loc_or_loc (expr, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (expr);
   bool dofold = (convtype & CONV_FOLD);
 
   if (error_operand_p (e) || type == error_mark_node)
@@ -1013,7 +1013,7 @@ maybe_warn_nodiscard (tree expr, impl_conv_void im
   tree call = expr;
   if (TREE_CODE (expr) == TARGET_EXPR)
     call = TARGET_EXPR_INITIAL (expr);
-  location_t loc = cp_expr_loc_or_loc (call, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (call);
   tree callee = cp_get_callee (call);
   if (!callee)
     return;
@@ -1093,7 +1093,7 @@ maybe_warn_nodiscard (tree expr, impl_conv_void im
 tree
 convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
 {
-  location_t loc = cp_expr_loc_or_loc (expr, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (expr);
 
   if (expr == error_mark_node
       || TREE_TYPE (expr) == error_mark_node)
Index: decl.c
===================================================================
--- decl.c	(revision 274001)
+++ decl.c	(working copy)
@@ -3560,7 +3560,7 @@ pop_switch (void)
   location_t switch_location;
 
   /* Emit warnings as needed.  */
-  switch_location = cp_expr_loc_or_loc (cs->switch_stmt, input_location);
+  switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
   const bool bool_cond_p
     = (SWITCH_STMT_TYPE (cs->switch_stmt)
        && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
Index: decl2.c
===================================================================
--- decl2.c	(revision 274001)
+++ decl2.c	(working copy)
@@ -489,7 +489,7 @@ delete_sanity (tree exp, tree size, bool doing_vec
   /* An array can't have been allocated by new, so complain.  */
   if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
       && (complain & tf_warning))
-    warning_at (cp_expr_loc_or_loc (exp, input_location), 0,
+    warning_at (cp_expr_loc_or_input_loc (exp), 0,
 		"deleting array %q#E", exp);
 
   t = build_expr_type_conversion (WANT_POINTER, exp, true);
@@ -497,7 +497,7 @@ delete_sanity (tree exp, tree size, bool doing_vec
   if (t == NULL_TREE || t == error_mark_node)
     {
       if (complain & tf_error)
-	error_at (cp_expr_loc_or_loc (exp, input_location),
+	error_at (cp_expr_loc_or_input_loc (exp),
 		  "type %q#T argument given to %<delete%>, expected pointer",
 		  TREE_TYPE (exp));
       return error_mark_node;
@@ -511,7 +511,7 @@ delete_sanity (tree exp, tree size, bool doing_vec
   if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
     {
       if (complain & tf_error)
-	error_at (cp_expr_loc_or_loc (exp, input_location),
+	error_at (cp_expr_loc_or_input_loc (exp),
 		  "cannot delete a function.  Only pointer-to-objects are "
 		  "valid arguments to %<delete%>");
       return error_mark_node;
@@ -521,8 +521,7 @@ delete_sanity (tree exp, tree size, bool doing_vec
   if (VOID_TYPE_P (TREE_TYPE (type)))
     {
       if (complain & tf_warning)
-	warning_at (cp_expr_loc_or_loc (exp, input_location),
-		    OPT_Wdelete_incomplete,
+	warning_at (cp_expr_loc_or_input_loc (exp), OPT_Wdelete_incomplete,
 		    "deleting %qT is undefined", type);
       doing_vec = 0;
     }
Index: error.c
===================================================================
--- error.c	(revision 274001)
+++ error.c	(working copy)
@@ -3053,7 +3053,7 @@ location_of (tree t)
     return DECL_SOURCE_LOCATION (t);
   if (TREE_CODE (t) == DEFERRED_PARSE)
     return defparse_location (t);
-  return cp_expr_loc_or_loc (t, input_location);
+  return cp_expr_loc_or_input_loc (t);
 }
 
 /* Now the interfaces from error et al to dump_type et al. Each takes an
Index: init.c
===================================================================
--- init.c	(revision 274001)
+++ init.c	(working copy)
@@ -749,7 +749,7 @@ maybe_warn_list_ctor (tree member, tree init)
   if (!begin)
     return;
 
-  location_t loc = cp_expr_loc_or_loc (init, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (init);
   warning_at (loc, OPT_Winit_list_lifetime,
 	     "initializing %qD from %qE does not extend the lifetime "
 	     "of the underlying array", member, begin);
@@ -1749,7 +1749,7 @@ build_aggr_init (tree exp, tree init, int flags, t
     return error_mark_node;
 
   location_t init_loc = (init
-			 ? cp_expr_loc_or_loc (init, input_location)
+			 ? cp_expr_loc_or_input_loc (init)
 			 : location_of (exp));
 
   TREE_READONLY (exp) = 0;
@@ -2578,7 +2578,7 @@ find_flexarray_init (tree t, tree init)
 static void
 warn_placement_new_too_small (tree type, tree nelts, tree size, tree oper)
 {
-  location_t loc = cp_expr_loc_or_loc (oper, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (oper);
 
   /* The number of bytes to add to or subtract from the size of the provided
      buffer based on an offset into an array or an array element reference.
@@ -2975,7 +2975,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree ty
 	{
 	  if (complain & tf_error)
 	    {
-	      error_at (cp_expr_loc_or_loc (inner_nelts, input_location),
+	      error_at (cp_expr_loc_or_input_loc (inner_nelts),
 			"array size in new-expression must be constant");
 	      cxx_constant_value(inner_nelts);
 	    }
@@ -3004,7 +3004,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree ty
     {
       if (complain & tf_warning_or_error)
 	{
-	  pedwarn (cp_expr_loc_or_loc (outer_nelts, input_location), OPT_Wvla,
+	  pedwarn (cp_expr_loc_or_input_loc (outer_nelts), OPT_Wvla,
 		   typedef_variant_p (orig_type)
 		   ? G_("non-constant array new length must be specified "
 			"directly, not by %<typedef%>")
@@ -4140,7 +4140,7 @@ build_vec_init (tree base, tree maxindex, tree ini
   tree obase = base;
   bool xvalue = false;
   bool errors = false;
-  location_t loc = (init ? cp_expr_loc_or_loc (init, input_location)
+  location_t loc = (init ? cp_expr_loc_or_input_loc (init)
 		    : location_of (base));
 
   if (TREE_CODE (atype) == ARRAY_TYPE && TYPE_DOMAIN (atype))
Index: lex.c
===================================================================
--- lex.c	(revision 274001)
+++ lex.c	(working copy)
@@ -502,7 +502,7 @@ tree
 unqualified_name_lookup_error (tree name, location_t loc)
 {
   if (loc == UNKNOWN_LOCATION)
-    loc = cp_expr_loc_or_loc (name, input_location);
+    loc = cp_expr_loc_or_input_loc (name);
 
   if (IDENTIFIER_ANY_OP_P (name))
     error_at (loc, "%qD not defined", name);
Index: parser.c
===================================================================
--- parser.c	(revision 274001)
+++ parser.c	(working copy)
@@ -23122,7 +23122,7 @@ cp_parser_initializer_list (cp_parser* parser, boo
 	  {
 	    if (IDENTIFIER_MARKED (designator))
 	      {
-		error_at (cp_expr_loc_or_loc (val, input_location),
+		error_at (cp_expr_loc_or_input_loc (val),
 			  "%<.%s%> designator used multiple times in "
 			  "the same initializer list",
 			  IDENTIFIER_POINTER (designator));
@@ -36632,7 +36632,7 @@ cp_parser_omp_for_cond (cp_parser *parser, tree de
 	  || CLASS_TYPE_P (TREE_TYPE (decl))))
     return cond;
 
-  return build_x_binary_op (cp_expr_loc_or_loc (cond, input_location),
+  return build_x_binary_op (cp_expr_loc_or_input_loc (cond),
 			    TREE_CODE (cond),
 			    TREE_OPERAND (cond, 0), ERROR_MARK,
 			    TREE_OPERAND (cond, 1), ERROR_MARK,
Index: pt.c
===================================================================
--- pt.c	(revision 274001)
+++ pt.c	(working copy)
@@ -4059,7 +4059,7 @@ check_for_bare_parameter_packs (tree t, location_t
   if (parameter_packs)
     {
       if (loc == UNKNOWN_LOCATION)
-	loc = cp_expr_loc_or_loc (t, input_location);
+	loc = cp_expr_loc_or_input_loc (t);
       error_at (loc, "parameter packs not expanded with %<...%>:");
       while (parameter_packs)
         {
@@ -6306,7 +6306,7 @@ static bool
 check_valid_ptrmem_cst_expr (tree type, tree expr,
 			     tsubst_flags_t complain)
 {
-  location_t loc = cp_expr_loc_or_loc (expr, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (expr);
   tree orig_expr = expr;
   STRIP_NOPS (expr);
   if (null_ptr_cst_p (expr))
@@ -6525,7 +6525,7 @@ unify_arg_conversion (bool explain_p, tree to_type
 		      tree from_type, tree arg)
 {
   if (explain_p)
-    inform (cp_expr_loc_or_loc (arg, input_location),
+    inform (cp_expr_loc_or_input_loc (arg),
 	    "  cannot convert %qE (type %qT) to type %qT",
 	    arg, from_type, to_type);
   return unify_invalid (explain_p);
@@ -6765,7 +6765,7 @@ static tree
 convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
 {
   tree expr_type;
-  location_t loc = cp_expr_loc_or_loc (expr, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (expr);
 
   /* Detect immediately string literals as invalid non-type argument.
      This special-case is not needed for correctness (we would easily
@@ -18965,10 +18965,10 @@ tsubst_copy_and_build (tree t,
 
 		    bool diag = true;
 		    if (in_lambda)
-		      error_at (cp_expr_loc_or_loc (t, input_location),
+		      error_at (cp_expr_loc_or_input_loc (t),
 				msg, function);
 		    else
-		      diag = permerror (cp_expr_loc_or_loc (t, input_location),
+		      diag = permerror (cp_expr_loc_or_input_loc (t),
 					msg, function);
 		    if (diag)
 		      {
@@ -18983,8 +18983,7 @@ tsubst_copy_and_build (tree t,
 			  /* Can't say anything more.  */;
 			else if (DECL_CLASS_SCOPE_P (fn))
 			  {
-			    location_t loc = cp_expr_loc_or_loc (t,
-							      input_location);
+			    location_t loc = cp_expr_loc_or_input_loc (t);
 			    inform (loc,
 				    "declarations in dependent base %qT are "
 				    "not found by unqualified lookup",
@@ -19032,14 +19031,13 @@ tsubst_copy_and_build (tree t,
 	      gcc_assert (nargs == 1);
 	      if (vec_safe_length (call_args) != 1)
 		{
-		  error_at (cp_expr_loc_or_loc (t, input_location),
+		  error_at (cp_expr_loc_or_input_loc (t),
 			    "wrong number of arguments to "
 			    "%<__builtin_launder%>");
 		  ret = error_mark_node;
 		}
 	      else
-		ret = finish_builtin_launder (cp_expr_loc_or_loc (t,
-							       input_location),
+		ret = finish_builtin_launder (cp_expr_loc_or_input_loc (t),
 					      (*call_args)[0], complain);
 	      break;
 
@@ -19047,7 +19045,7 @@ tsubst_copy_and_build (tree t,
 	      gcc_assert (nargs == 1);
 	      if (vec_safe_length (call_args) != 1)
 		{
-		  error_at (cp_expr_loc_or_loc (t, input_location),
+		  error_at (cp_expr_loc_or_input_loc (t),
 			    "wrong number of arguments to "
 			    "%<__builtin_convertvector%>");
 		  ret = error_mark_node;
@@ -26595,7 +26593,7 @@ resolve_typename_type (tree type, bool only_curren
 
 	     [temp.names]: In a qualified-id of a declarator-id, the keyword
 	     template shall not appear at the top level.  */
-	  pedwarn (cp_expr_loc_or_loc (fullname, input_location), OPT_Wpedantic,
+	  pedwarn (cp_expr_loc_or_input_loc (fullname), OPT_Wpedantic,
 		   "keyword %<template%> not allowed in declarator-id");
 	  tmpl = decl;
 	}
Index: semantics.c
===================================================================
--- semantics.c	(revision 274001)
+++ semantics.c	(working copy)
@@ -658,7 +658,7 @@ maybe_convert_cond (tree cond)
   if (TREE_CODE (cond) == MODIFY_EXPR
       && !TREE_NO_WARNING (cond)
       && warn_parentheses
-      && warning_at (cp_expr_loc_or_loc (cond, input_location),
+      && warning_at (cp_expr_loc_or_input_loc (cond),
 		     OPT_Wparentheses, "suggest parentheses around "
 				       "assignment used as truth value"))
     TREE_NO_WARNING (cond) = 1;
@@ -2426,7 +2426,7 @@ finish_call_expr (tree fn, vec<tree, va_gc> **args
 	  || any_type_dependent_arguments_p (*args))
 	{
 	  result = build_min_nt_call_vec (orig_fn, *args);
-	  SET_EXPR_LOCATION (result, cp_expr_loc_or_loc (fn, input_location));
+	  SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
 	  KOENIG_LOOKUP_P (result) = koenig_p;
 	  if (is_overloaded_fn (fn))
 	    fn = get_fns (fn);
@@ -10102,7 +10102,7 @@ cp_build_vec_convert (tree arg, location_t loc, tr
 
   tree ret = NULL_TREE;
   if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
-    ret = c_build_vec_convert (cp_expr_loc_or_loc (arg, input_location), arg,
+    ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg), arg,
 			       loc, type, (complain & tf_error) != 0);
 
   if (!processing_template_decl)
Index: typeck.c
===================================================================
--- typeck.c	(revision 274001)
+++ typeck.c	(working copy)
@@ -2020,7 +2020,7 @@ decay_conversion (tree exp,
 {
   tree type;
   enum tree_code code;
-  location_t loc = cp_expr_loc_or_loc (exp, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (exp);
 
   type = TREE_TYPE (exp);
   if (type == error_mark_node)
@@ -2281,7 +2281,7 @@ static tree
 rationalize_conditional_expr (enum tree_code code, tree t,
                               tsubst_flags_t complain)
 {
-  location_t loc = cp_expr_loc_or_loc (t, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (t);
 
   /* For MIN_EXPR or MAX_EXPR, fold-const.c has arranged things so that
      the first operand is always the one to be used if both operands
@@ -6206,7 +6206,7 @@ cp_build_unary_op (enum tree_code code, tree xarg,
 {
   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
   tree arg = xarg;
-  location_t location = cp_expr_loc_or_loc (arg, input_location);
+  location_t location = cp_expr_loc_or_input_loc (arg);
   tree argtype = 0;
   const char *errstring = NULL;
   tree val;
@@ -6760,7 +6760,7 @@ build_x_compound_expr_from_list (tree list, expr_l
       && !CONSTRUCTOR_IS_DIRECT_INIT (expr))
     {
       if (complain & tf_error)
-	pedwarn (cp_expr_loc_or_loc (expr, input_location), 0,
+	pedwarn (cp_expr_loc_or_input_loc (expr), 0,
 		 "list-initializer for non-class type must not "
 		 "be parenthesized");
       else
@@ -9210,7 +9210,7 @@ maybe_warn_about_returning_address_of_local (tree
 {
   tree valtype = TREE_TYPE (DECL_RESULT (current_function_decl));
   tree whats_returned = fold_for_warn (retval);
-  location_t loc = cp_expr_loc_or_loc (retval, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (retval);
 
   for (;;)
     {
@@ -9420,7 +9420,7 @@ maybe_warn_pessimizing_move (tree retval, tree fun
   if (!(warn_pessimizing_move || warn_redundant_move))
     return;
 
-  location_t loc = cp_expr_loc_or_loc (retval, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (retval);
 
   /* C++98 doesn't know move.  */
   if (cxx_dialect < cxx11)
Index: typeck2.c
===================================================================
--- typeck2.c	(revision 274001)
+++ typeck2.c	(working copy)
@@ -1006,7 +1006,7 @@ check_narrowing (tree type, tree init, tsubst_flag
 
   if (!ok)
     {
-      location_t loc = cp_expr_loc_or_loc (init, input_location);
+      location_t loc = cp_expr_loc_or_input_loc (init);
       if (cxx_dialect == cxx98)
 	{
 	  if (complain & tf_warning)
@@ -1085,7 +1085,7 @@ digest_init_r (tree type, tree init, int nested, i
 					complain))
     return error_mark_node;
 
-  location_t loc = cp_expr_loc_or_loc (init, input_location);
+  location_t loc = cp_expr_loc_or_input_loc (init);
 
   tree stripped_init = init;
 
@@ -1402,7 +1402,7 @@ process_init_constructor_array (tree type, tree in
       if (nested == 2 && !domain && !vec_safe_is_empty (v))
 	{
 	  if (complain & tf_error)
-	    error_at (cp_expr_loc_or_loc (init, input_location),
+	    error_at (cp_expr_loc_or_input_loc (init),
 		      "initialization of flexible array member "
 		      "in a nested context");
 	  return PICFLAG_ERRONEOUS;
David Malcolm Aug. 2, 2019, 12:27 p.m. UTC | #4
On Fri, 2019-08-02 at 14:02 +0200, Paolo Carlini wrote:
> Hi,
> 
> On 31/07/19 21:39, David Malcolm wrote:
> 
> [snip]
> > I don't care for "cp_expr_loc_or_loc".
> > 
> > By "_or_here" do you mean "or input_location"?
> > 
> > Calling it "cp_expr_loc_or_input_location" would spell out what it
> > does, but would be rather long.
> 
> Thanks for your feedback. At this point I don't feel very strongly
> about 
> the issue, and, well, hopefully it's just temporary material, but I 
> tested the below which proposes the name cp_expr_loc_or_input_loc.
> Seems 
> a good balance to me. What do you think?

I like it, FWIW.

Thanks
Dave
Jason Merrill Aug. 5, 2019, 7:06 p.m. UTC | #5
On 8/2/19 8:27 AM, David Malcolm wrote:
> On Fri, 2019-08-02 at 14:02 +0200, Paolo Carlini wrote:
>> Hi,
>>
>> On 31/07/19 21:39, David Malcolm wrote:
>>
>> [snip]
>>> I don't care for "cp_expr_loc_or_loc".
>>>
>>> By "_or_here" do you mean "or input_location"?
>>>
>>> Calling it "cp_expr_loc_or_input_location" would spell out what it
>>> does, but would be rather long.
>>
>> Thanks for your feedback. At this point I don't feel very strongly
>> about
>> the issue, and, well, hopefully it's just temporary material, but I
>> tested the below which proposes the name cp_expr_loc_or_input_loc.
>> Seems
>> a good balance to me. What do you think?
> 
> I like it, FWIW.

OK.

Jason
diff mbox series

Patch

Index: cp/decl2.c
===================================================================
--- cp/decl2.c	(revision 273767)
+++ cp/decl2.c	(working copy)
@@ -487,15 +487,19 @@  delete_sanity (tree exp, tree size, bool doing_vec
     }
 
   /* 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,8 +510,10 @@  delete_sanity (tree exp, tree size, bool doing_vec
   /* 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;
     }
 
@@ -514,7 +520,10 @@  delete_sanity (tree exp, tree size, bool doing_vec
   /* 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: testsuite/g++.dg/diagnostic/delete1.C
===================================================================
--- testsuite/g++.dg/diagnostic/delete1.C	(nonexistent)
+++ testsuite/g++.dg/diagnostic/delete1.C	(working copy)
@@ -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*." }
+}