diff mbox

minor C++ PATCH to improve ambiguous conversion diagnostics

Message ID 4C17DCE8.7080002@redhat.com
State New
Headers show

Commit Message

Jason Merrill June 15, 2010, 8:04 p.m. UTC
I noticed we weren't giving the "initializing parameter N of foo(bar)" 
message for ambiguous conversions that we give for other conversion 
errors.  I also moved that message to the site of the function 
declaration, since we already have a message at the call site.

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

Patch

commit 02b8944317de822b7d231fd4d3ec7f0d367821c8
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jun 14 10:08:22 2010 -0400

    	* call.c (convert_like_real): Give "initializing argument of"
    	information for ambiguous conversion.  Give source position
    	of function.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index a735dc6..55089ed 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4934,7 +4934,8 @@  convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
 	{
 	  permerror (input_location, "invalid conversion from %qT to %qT", TREE_TYPE (expr), totype);
 	  if (fn)
-	    permerror (input_location, "  initializing argument %P of %qD", argnum, fn);
+	    permerror (DECL_SOURCE_LOCATION (fn),
+		       "  initializing argument %P of %qD", argnum, fn);
 	}
       else
 	return error_mark_node;
@@ -5018,11 +5019,14 @@  convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
         }
       return expr;
     case ck_ambig:
-      if (!(complain & tf_error))
-	return error_mark_node;
-      /* Call build_user_type_conversion again for the error.  */
-      return build_user_type_conversion
-	(totype, convs->u.expr, LOOKUP_NORMAL);
+      if (complain & tf_error)
+	{
+	  /* Call build_user_type_conversion again for the error.  */
+	  build_user_type_conversion (totype, convs->u.expr, LOOKUP_NORMAL);
+	  if (fn)
+	    error ("  initializing argument %P of %q+D", argnum, fn);
+	}
+      return error_mark_node;
 
     case ck_list:
       {
@@ -5110,7 +5114,7 @@  convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
       if (diag_kind && fn)
 	{
 	  if ((complain & tf_error))
-	    emit_diagnostic (diag_kind, input_location, 0, 
+	    emit_diagnostic (diag_kind, DECL_SOURCE_LOCATION (fn), 0,
 			     "  initializing argument %P of %qD", argnum, fn);
 	  else if (diag_kind == DK_ERROR)
 	    return error_mark_node;
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist15.C b/gcc/testsuite/g++.dg/cpp0x/initlist15.C
index d59e5af..b75cc81 100644
--- a/gcc/testsuite/g++.dg/cpp0x/initlist15.C
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist15.C
@@ -1,5 +1,8 @@ 
 // { dg-options "-std=c++0x" }
 
+// Just discard errors pointing at header files
+// { dg-prune-output "include" }
+
 #include <vector>
 #include <typeinfo>
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist19.C b/gcc/testsuite/g++.dg/cpp0x/initlist19.C
index 418cddc..9cb197c 100644
--- a/gcc/testsuite/g++.dg/cpp0x/initlist19.C
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist19.C
@@ -1,8 +1,10 @@ 
 // { dg-options "-std=c++0x" }
 
+// Allow other errors, too
+// { dg-prune-output "error" }
+
 void f(double);
 int main()
 {
   f({{1}});			// { dg-error "too many braces" }
-  // { dg-error "" "" { target *-*-* } 6 } allow other errors, too
 }
diff --git a/gcc/testsuite/g++.dg/expr/cond8.C b/gcc/testsuite/g++.dg/expr/cond8.C
index f05c81a..11708ec 100644
--- a/gcc/testsuite/g++.dg/expr/cond8.C
+++ b/gcc/testsuite/g++.dg/expr/cond8.C
@@ -3,11 +3,11 @@ 
 
 struct A
 {
-  A(void*);
+  A(void*);			// { dg-error "initializing" }
   ~A();
 };
 
 void foo(const int i, bool b)
 {
-  b ? A(0) : i; // { dg-error "conversion|initializing" } 
+  b ? A(0) : i; // { dg-error "conversion" }
 }
diff --git a/gcc/testsuite/g++.old-deja/g++.bugs/900514_03.C b/gcc/testsuite/g++.old-deja/g++.bugs/900514_03.C
index 3826e08..c06cef1 100644
--- a/gcc/testsuite/g++.old-deja/g++.bugs/900514_03.C
+++ b/gcc/testsuite/g++.old-deja/g++.bugs/900514_03.C
@@ -16,7 +16,7 @@ 
 
 struct t_0_st_0;
 
-struct t_0_st_1 {
+struct t_0_st_1 {		// { dg-error "initializing" }
   int member;
 
   t_0_st_1 (t_0_st_0&);// { dg-message "note" } 
@@ -83,7 +83,7 @@  void t_1_local_init ()
 
 struct t_2_st_0;
 
-struct t_2_st_1 {
+struct t_2_st_1 {		// { dg-error "initializing" }
   int member;
 
   t_2_st_1 (t_2_st_0);		// { dg-message "note" }
diff --git a/libstdc++-v3/testsuite/ext/ext_pointer/1_neg.cc b/libstdc++-v3/testsuite/ext/ext_pointer/1_neg.cc
index bab32fa..c599aca 100644
--- a/libstdc++-v3/testsuite/ext/ext_pointer/1_neg.cc
+++ b/libstdc++-v3/testsuite/ext/ext_pointer/1_neg.cc
@@ -92,12 +92,7 @@  void test01(void) {
 }
 
 // { dg-error "invalid conversion " "" { target *-*-* } 314 }
-// { dg-error "initializing argument 1 of" "" { target *-*-* } 314 }
 // { dg-error "invalid conversion " "" { target *-*-* } 308 }
-// { dg-error "initializing argument 1 of" "" { target *-*-* } 308 }
 // { dg-error "invalid conversion " "" { target *-*-* } 331 }
-// { dg-error "initializing argument 1 of" "" { target *-*-* } 331 }
 // { dg-error "invalid conversion " "" { target *-*-* } 339 }
-// { dg-error "initializing argument 1 of" "" { target *-*-* } 339 }
 // { dg-excess-errors "In constructor" }
-