diff mbox series

[pushed] c++: adjust conversion diagnostics

Message ID 20230510210731.975161-1-jason@redhat.com
State New
Headers show
Series [pushed] c++: adjust conversion diagnostics | expand

Commit Message

Jason Merrill May 10, 2023, 9:07 p.m. UTC
Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

While looking at PR109247 I made this change to improve diagnostics.  I
don't think I'm going ahead with that patch, but this still seems like a
worthy cleanup.

gcc/cp/ChangeLog:

	* call.cc (convert_like_internal): Share ck_ref_bind handling
	between all bad conversions.
---
 gcc/cp/call.cc | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)


base-commit: 8d46516a61a83d24ba89086071f65a194d82ce4e
diff mbox series

Patch

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 2a06520c0c1..48611bb16a3 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -8360,15 +8360,6 @@  convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
 				   /*issue_conversion_warnings=*/false,
 				   /*c_cast_p=*/false, /*nested_p=*/true,
 				   complain);
-	      if (convs->kind == ck_ref_bind)
-		expr = convert_to_reference (totype, expr, CONV_IMPLICIT,
-					     LOOKUP_NORMAL, NULL_TREE,
-					     complain);
-	      else
-		expr = cp_convert (totype, expr, complain);
-	      if (complained)
-		maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
-	      return expr;
 	    }
 	  else if (t->kind == ck_user || !t->bad_p)
 	    {
@@ -8376,6 +8367,8 @@  convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
 				   /*issue_conversion_warnings=*/false,
 				   /*c_cast_p=*/false, /*nested_p=*/true,
 				   complain);
+	      if (t->bad_p)
+		complained = 1;
 	      break;
 	    }
 	  else if (t->kind == ck_ambig)
@@ -8394,10 +8387,15 @@  convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
 				  "invalid conversion from %qH to %qI",
 				  TREE_TYPE (expr), totype);
 	}
+      if (convs->kind == ck_ref_bind)
+	expr = convert_to_reference (totype, expr, CONV_IMPLICIT,
+				     LOOKUP_NORMAL, NULL_TREE,
+				     complain);
+      else
+	expr = cp_convert (totype, expr, complain);
       if (complained == 1)
 	maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
-
-      return cp_convert (totype, expr, complain);
+      return expr;
     }
 
   if (issue_conversion_warnings && (complain & tf_warning))