public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-77] c++: improve template-id location
@ 2022-05-02 22:05 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-05-02 22:05 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6f78c52d4bd08caec4f3b11ad2302e7cde044c1e

commit r13-77-g6f78c52d4bd08caec4f3b11ad2302e7cde044c1e
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Apr 30 05:45:02 2022 -0400

    c++: improve template-id location
    
    On PR102629 I noticed that we were giving the entire lambda as the location
    for this template-id.
    
    gcc/cp/ChangeLog:
    
            * pt.cc (tsubst_copy_and_build) [TEMPLATE_ID_EXPR]: Copy location.
            (do_auto_deduction): Use expr location.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/lambda-pack-init7.C: Check column number.

Diff:
---
 gcc/cp/pt.cc                                   | 28 +++++++++++++++-----------
 gcc/testsuite/g++.dg/cpp2a/lambda-pack-init7.C |  2 +-
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 23fbd8245d4..3edee50924f 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -20091,6 +20091,7 @@ tsubst_copy_and_build (tree t,
 	  object = NULL_TREE;
 
 	tree tid = lookup_template_function (templ, targs);
+	protected_set_expr_location (tid, EXPR_LOCATION (t));
 
 	if (object)
 	  RETURN (build3 (COMPONENT_REF, TREE_TYPE (tid),
@@ -30181,6 +30182,8 @@ do_auto_deduction (tree type, tree init, tree auto_node,
     /* Nothing we can do with this, even in deduction context.  */
     return type;
 
+  location_t loc = cp_expr_loc_or_input_loc (init);
+
   /* [dcl.spec.auto]: Obtain P from T by replacing the occurrences of auto
      with either a new invented type template parameter U or, if the
      initializer is a braced-init-list (8.5.4), with
@@ -30195,9 +30198,9 @@ do_auto_deduction (tree type, tree init, tree auto_node,
 	{
           if (complain & tf_warning_or_error)
             {
-	      if (permerror (input_location, "direct-list-initialization of "
+	      if (permerror (loc, "direct-list-initialization of "
 			     "%<auto%> requires exactly one element"))
-	        inform (input_location,
+		inform (loc,
 		        "for deduction to %<std::initializer_list%>, use copy-"
 		        "list-initialization (i.e. add %<=%> before the %<{%>)");
             }
@@ -30288,9 +30291,10 @@ do_auto_deduction (tree type, tree init, tree auto_node,
 		  && (auto_node
 		      == DECL_SAVED_AUTO_RETURN_TYPE (current_function_decl))
 		  && LAMBDA_FUNCTION_P (current_function_decl))
-		error ("unable to deduce lambda return type from %qE", init);
+		error_at (loc, "unable to deduce lambda return type from %qE",
+			  init);
 	      else
-		error ("unable to deduce %qT from %qE", type, init);
+		error_at (loc, "unable to deduce %qT from %qE", type, init);
 	      type_unification_real (tparms, targs, parms, &init, 1, 0,
 				     DEDUCE_CALL,
 				     NULL, /*explain_p=*/true);
@@ -30362,23 +30366,23 @@ do_auto_deduction (tree type, tree init, tree auto_node,
 		{
 		case adc_unspecified:
 		case adc_unify:
-		  error("placeholder constraints not satisfied");
+		  error_at (loc, "placeholder constraints not satisfied");
 		  break;
 		case adc_variable_type:
 		case adc_decomp_type:
-		  error ("deduced initializer does not satisfy "
-			 "placeholder constraints");
+		  error_at (loc, "deduced initializer does not satisfy "
+			    "placeholder constraints");
 		  break;
 		case adc_return_type:
-		  error ("deduced return type does not satisfy "
-			 "placeholder constraints");
+		  error_at (loc, "deduced return type does not satisfy "
+			    "placeholder constraints");
 		  break;
 		case adc_requirement:
-		  error ("deduced expression type does not satisfy "
-			 "placeholder constraints");
+		  error_at (loc, "deduced expression type does not satisfy "
+			    "placeholder constraints");
 		  break;
 		}
-	      diagnose_constraints (input_location, auto_node, full_targs);
+	      diagnose_constraints (loc, auto_node, full_targs);
 	    }
 	  return error_mark_node;
 	}
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init7.C b/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init7.C
index f3c3899e97a..face7258c2e 100644
--- a/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init7.C
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init7.C
@@ -8,7 +8,7 @@ struct S {};
 
 template <typename... Args>
 void foo(Args&&... args) {
-  [...args = forward<Args> /*(args)*/] { // { dg-error "" }
+  [...args = forward<Args> /*(args)*/] { // { dg-error "14:" }
     [](auto...) { } (forward<Args>(args)...);
   };
 }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-02 22:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-02 22:05 [gcc r13-77] c++: improve template-id location Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).