On PR102629 I noticed that we were giving the entire lambda as the location
for this template-id.

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

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.
---
 gcc/cp/pt.cc                                  | 28 +++++++++++--------
 .../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)...);
   };
 }

base-commit: dcb4bd0789d13dd4d07428bff712d01d3ea71ebe
-- 
2.27.0

Reply via email to