diff mbox

C++ PATCH to convert_like_real diagnostics

Message ID 53718FA5.8020703@redhat.com
State New
Headers show

Commit Message

Jason Merrill May 13, 2014, 3:21 a.m. UTC
Some small changes adding more context to conversion diagnostics.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit f84b4d6a1ef681f0070d1df7302ca76bb5918526
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Apr 20 20:20:22 2014 -0400

    	* call.c (maybe_print_user_conv_context): New.
    	(convert_like_real): Use it.  Print call context for bad
    	user-defined conversion.
    	(build_over_call): Print call context for bad 'this' conversion.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index f2ceef2..7b8bc09 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -5942,6 +5942,23 @@  conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
     }
 }
 
+/* We gave a diagnostic during a conversion.  If this was in the second
+   standard conversion sequence of a user-defined conversion sequence, say
+   which user-defined conversion.  */
+
+static void
+maybe_print_user_conv_context (conversion *convs)
+{
+  if (convs->user_conv_p)
+    for (conversion *t = convs; t; t = next_conversion (t))
+      if (t->kind == ck_user)
+	{
+	  print_z_candidate (0, "  after user-defined conversion:",
+			     t->cand);
+	  break;
+	}
+}
+
 /* Perform the conversions in CONVS on the expression EXPR.  FN and
    ARGNUM are used for diagnostics.  ARGNUM is zero based, -1
    indicates the `this' argument of a method.  INNER is nonzero when
@@ -6003,11 +6020,15 @@  convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
 					/*c_cast_p=*/false,
 					complain);
 	      if (convs->kind == ck_ref_bind)
-		return convert_to_reference (totype, expr, CONV_IMPLICIT,
+		expr = convert_to_reference (totype, expr, CONV_IMPLICIT,
 					     LOOKUP_NORMAL, NULL_TREE,
 					     complain);
 	      else
-		return cp_convert (totype, expr, complain);
+		expr = cp_convert (totype, expr, complain);
+	      if (fn)
+		inform (DECL_SOURCE_LOCATION (fn),
+			"  initializing argument %P of %qD", argnum, fn);
+	      return expr;
 	    }
 	  else if (t->kind == ck_user || !t->bad_p)
 	    {
@@ -6030,7 +6051,7 @@  convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
 				TREE_TYPE (expr), totype);
       if (complained && fn)
 	inform (DECL_SOURCE_LOCATION (fn),
-		"initializing argument %P of %qD", argnum, fn);
+		"  initializing argument %P of %qD", argnum, fn);
 
       return cp_convert (totype, expr, complain);
     }
@@ -6135,7 +6156,7 @@  convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
 	  build_user_type_conversion (totype, convs->u.expr, LOOKUP_NORMAL,
 				      complain);
 	  if (fn)
-	    inform (input_location, "initializing argument %P of %q+D",
+	    inform (input_location, "  initializing argument %P of %q+D",
 		    argnum, fn);
 	}
       return error_mark_node;
@@ -6255,9 +6276,14 @@  convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
 	/* Copy-list-initialization doesn't actually involve a copy.  */
 	return expr;
       expr = build_temp (expr, totype, flags, &diag_kind, complain);
-      if (diag_kind && fn && complain)
-	inform (DECL_SOURCE_LOCATION (fn),
-		"  initializing argument %P of %qD", argnum, fn);
+      if (diag_kind && complain)
+	{
+	  maybe_print_user_conv_context (convs);
+	  if (fn)
+	    inform (DECL_SOURCE_LOCATION (fn),
+		    "  initializing argument %P of %qD", argnum, fn);
+	}
+
       return build_cplus_new (totype, expr, complain);
 
     case ck_ref_bind:
@@ -6272,9 +6298,10 @@  convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
 
 	    error_at (loc, "cannot bind %qT lvalue to %qT",
 		      TREE_TYPE (expr), totype);
+	    maybe_print_user_conv_context (convs);
 	    if (fn)
 	      inform (input_location,
-		      "initializing argument %P of %q+D", argnum, fn);
+		      "  initializing argument %P of %q+D", argnum, fn);
 	    return error_mark_node;
 	  }
 
@@ -6935,8 +6962,12 @@  build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
       if (convs[i]->bad_p)
 	{
 	  if (complain & tf_error)
-	    permerror (input_location, "passing %qT as %<this%> argument of %q#D discards qualifiers",
-		       TREE_TYPE (argtype), fn);
+	    {
+	      if (permerror (input_location, "passing %qT as %<this%> "
+			     "argument discards qualifiers",
+			     TREE_TYPE (argtype)))
+		inform (DECL_SOURCE_LOCATION (fn), "  in call to %qD", fn);
+	    }
 	  else
 	    return error_mark_node;
 	}