From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id D501B3857355; Mon, 2 May 2022 22:05:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D501B3857355 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-77] c++: improve template-id location X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/master X-Git-Oldrev: dcb4bd0789d13dd4d07428bff712d01d3ea71ebe X-Git-Newrev: 6f78c52d4bd08caec4f3b11ad2302e7cde044c1e Message-Id: <20220502220559.D501B3857355@sourceware.org> Date: Mon, 2 May 2022 22:05:59 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 May 2022 22:05:59 -0000 https://gcc.gnu.org/g:6f78c52d4bd08caec4f3b11ad2302e7cde044c1e commit r13-77-g6f78c52d4bd08caec4f3b11ad2302e7cde044c1e Author: Jason Merrill 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 " "% requires exactly one element")) - inform (input_location, + inform (loc, "for deduction to %, 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 void foo(Args&&... args) { - [...args = forward /*(args)*/] { // { dg-error "" } + [...args = forward /*(args)*/] { // { dg-error "14:" } [](auto...) { } (forward(args)...); }; }