From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 97C5C3858401 for ; Thu, 1 Jun 2023 15:43:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97C5C3858401 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685634191; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ONxoOphF9pxvA3fI0sE+EeT7e24+GhvRrEkOndfBjtc=; b=DcAqyGB6GNGRWpPPOK67gX8QpkbBFKfpU5zt/qbFCrs1e/m93LuZWNeOJyF+Jd9D1p2YaO uPXvcXH/N3QjncgUj8QkxMGjWtWMAIVqNLSTEaZnrVF/i9z0drvuywZk1Qb9YWVXJW1GhL 1HishLWb+l1uMAFJMx1At28NPr+InfA= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-583-VTBQNf5fPcmYpkeCS_-Hzw-1; Thu, 01 Jun 2023 11:43:10 -0400 X-MC-Unique: VTBQNf5fPcmYpkeCS_-Hzw-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2b0227e61c1so9224871fa.3 for ; Thu, 01 Jun 2023 08:43:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685634189; x=1688226189; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ONxoOphF9pxvA3fI0sE+EeT7e24+GhvRrEkOndfBjtc=; b=hG5MprT4OCEwrKmxSDYxxscpYBMLwXR9M2287fILUGcgKa1Q7jymrlmHdgqOOeDP1U pkmYTQcLqM0hFgIXBCw0DxAZ+im9Dpy3eP2xdcw5h0ca9iWLiS8WHaOuNKYBC/kUICJ0 S91afCL/EMMy2KLqMojk4IGadl+CQFasoFbaWGHejmB4/eX1LATu9QAXVQilRA+iHq6T RQgt5rPhBTzOpCGNfnMRIWfv6YFvHWaobgtR8jBI0c9x74ZAZwcaUXBHNP4W8x2QRj1T rfPxvWbObFCLU731pGpdQeNqfZ1GET4GRxutFu9kV01lGdW0FjDUaW8loZg00S1+TB8n 5M6g== X-Gm-Message-State: AC+VfDyb7AU7oPRMBw7B7MxkN0n63b5nW0PIcbZ4TsFe3OLIfu8H1Iyx 7yBzVF/OUq+4KvkI1e/Vx4djQVkW68zxb5/XV+7znRSyNkVXBrBii3hf3mfZGKD2SYcls8ezR2g 3YDsOKnqXXvkbN1ZiN1spptnizu2tpY+u+sc8c/EhiA== X-Received: by 2002:a2e:868e:0:b0:2af:30d8:527f with SMTP id l14-20020a2e868e000000b002af30d8527fmr5231673lji.19.1685634188731; Thu, 01 Jun 2023 08:43:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5C5pics5OsKPOpTDyQ/6uSbsuSz6tJ8BS8Vk7ZoCnHBeujQxy1/JGGziutNomFy0AiU5AWO2uliJ28mz9Tveg= X-Received: by 2002:a2e:868e:0:b0:2af:30d8:527f with SMTP id l14-20020a2e868e000000b002af30d8527fmr5231660lji.19.1685634188281; Thu, 01 Jun 2023 08:43:08 -0700 (PDT) MIME-Version: 1.0 References: <20230503135043.273442-1-ppalka@redhat.com> In-Reply-To: <20230503135043.273442-1-ppalka@redhat.com> From: Patrick Palka Date: Thu, 1 Jun 2023 11:42:57 -0400 Message-ID: Subject: Re: [PATCH] c++: ahead of time variable template-id coercion [PR89442] To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, May 3, 2023 at 9:50=E2=80=AFAM Patrick Palka wr= ote: > > This patch makes us coerce the arguments of a variable template-id ahead > of time, as we do for other template-ids, which allows us to immediately > diagnose template parameter/argument kind mismatches and arity mismatches= . > > Unfortunately this causes a regression in cpp1z/constexpr-if20.C: coercin= g > the variable template-id m ahead of time means we strip it of > typedefs, yielding m::q, typename C::q>, but in this > stripped form we're directly using 'i' and so we expect to have captured > it. This is PR107437 but with a variable template instead of a class > template. I'm not sure how to fix this :( > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? Ping. > > PR c++/89442 > PR c++/107437 > > gcc/cp/ChangeLog: > > * cp-tree.h (lookup_template_variable): Add complain parameter. > * parser.cc (cp_parser_template_id): Pass tf_warning_or_error > to lookup_template_variable. > * pt.cc (lookup_template_variable): Add complain parameter. > Coerce template arguments here ... > (finish_template_variable): ... instead of here. > (lookup_and_finish_template_variable): Check for error_mark_node > result from lookup_template_variable. > (tsubst_copy) : Pass complain to > lookup_template_variable. > (instantiate_template): Use build2 instead of > lookup_template_variable to build a TEMPLATE_ID_EXPR > for most_specialized_partial_spec. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp/pr64127.C: Expect "expected unqualified-id at end > of input" error. > * g++.dg/cpp0x/alias-decl-ttp1.C: Fix template parameter/argument > kind mismatch for variable template has_P_match_V. > * g++.dg/cpp1y/pr72759.C: Expect "template argument 1 is invalid" > error. > * g++.dg/cpp1z/constexpr-if20.C: XFAIL test due to bogus "'i' is > not captured" error. > * g++.dg/cpp1z/noexcept-type21.C: Fix arity of variable template = d. > * g++.dg/diagnostic/not-a-function-template-1.C: Add default > template argument to variable template A so that A<> is valid. > * g++.dg/parse/error56.C: Don't expect "ISO C++ forbids > declaration with no type" error. > * g++.dg/parse/template30.C: Don't expect "parse error in > template argument list" error. > * g++.dg/cpp1y/var-templ80.C: New test. > --- > gcc/cp/cp-tree.h | 2 +- > gcc/cp/parser.cc | 2 +- > gcc/cp/pt.cc | 20 ++++++++++--------- > gcc/testsuite/g++.dg/cpp/pr64127.C | 2 +- > gcc/testsuite/g++.dg/cpp0x/alias-decl-ttp1.C | 2 +- > gcc/testsuite/g++.dg/cpp1y/pr72759.C | 2 +- > gcc/testsuite/g++.dg/cpp1y/var-templ80.C | 12 +++++++++++ > gcc/testsuite/g++.dg/cpp1z/constexpr-if20.C | 1 + > gcc/testsuite/g++.dg/cpp1z/noexcept-type21.C | 2 +- > .../diagnostic/not-a-function-template-1.C | 2 +- > gcc/testsuite/g++.dg/parse/error56.C | 1 - > gcc/testsuite/g++.dg/parse/template30.C | 3 +-- > 12 files changed, 32 insertions(+), 19 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ80.C > > diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h > index c9c4cd6f32f..96807282ec5 100644 > --- a/gcc/cp/cp-tree.h > +++ b/gcc/cp/cp-tree.h > @@ -7349,7 +7349,7 @@ extern bool redeclare_class_template (= tree, tree, tree); > extern tree lookup_template_class (tree, tree, tree, tree, > int, tsubst_flags_t); > extern tree lookup_template_function (tree, tree); > -extern tree lookup_template_variable (tree, tree); > +extern tree lookup_template_variable (tree, tree, tsubst_flags= _t); > extern bool uses_template_parms (tree); > extern bool uses_template_parms_level (tree, int); > extern bool uses_outer_template_parms_in_constraints (tree); > diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc > index d89553e7da8..4982583809b 100644 > --- a/gcc/cp/parser.cc > +++ b/gcc/cp/parser.cc > @@ -18525,7 +18525,7 @@ cp_parser_template_id (cp_parser *parser, > } > else if (variable_template_p (templ)) > { > - template_id =3D lookup_template_variable (templ, arguments); > + template_id =3D lookup_template_variable (templ, arguments, tf_war= ning_or_error); > if (TREE_CODE (template_id) =3D=3D TEMPLATE_ID_EXPR) > SET_EXPR_LOCATION (template_id, combined_loc); > } > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 930291917f2..abf99feab20 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -10329,11 +10329,16 @@ lookup_template_class (tree d1, tree arglist, t= ree in_decl, tree context, > /* Return a TEMPLATE_ID_EXPR for the given variable template and ARGLIST= . */ > > tree > -lookup_template_variable (tree templ, tree arglist) > +lookup_template_variable (tree templ, tree arglist, tsubst_flags_t compl= ain) > { > if (flag_concepts && variable_concept_p (templ)) > return build_concept_check (templ, arglist, tf_none); > > + tree parms =3D DECL_INNERMOST_TEMPLATE_PARMS (templ); > + arglist =3D coerce_template_parms (parms, arglist, templ, complain); > + if (arglist =3D=3D error_mark_node) > + return error_mark_node; > + > /* The type of the expression is NULL_TREE since the template-id could= refer > to an explicit or partial specialization. */ > return build2 (TEMPLATE_ID_EXPR, NULL_TREE, templ, arglist); > @@ -10354,11 +10359,6 @@ finish_template_variable (tree var, tsubst_flags= _t complain) > || any_dependent_template_arguments_p (arglist)) > return var; > > - tree parms =3D DECL_TEMPLATE_PARMS (templ); > - arglist =3D coerce_template_parms (parms, arglist, templ, complain); > - if (arglist =3D=3D error_mark_node) > - return error_mark_node; > - > if (flag_concepts && !constraints_satisfied_p (templ, arglist)) > { > if (complain & tf_error) > @@ -10380,7 +10380,9 @@ tree > lookup_and_finish_template_variable (tree templ, tree targs, > tsubst_flags_t complain) > { > - tree var =3D lookup_template_variable (templ, targs); > + tree var =3D lookup_template_variable (templ, targs, complain); > + if (var =3D=3D error_mark_node) > + return error_mark_node; > /* We may be called while doing a partial substitution, but the > type of the variable template may be auto, in which case we > will call do_auto_deduction in mark_used (which clears tf_partial) > @@ -17793,7 +17795,7 @@ tsubst_copy (tree t, tree args, tsubst_flags_t co= mplain, tree in_decl) > targs =3D tsubst_template_args (targs, args, complain, in_decl)= ; > > if (variable_template_p (tmpl)) > - return lookup_template_variable (tmpl, targs); > + return lookup_template_variable (tmpl, targs, complain); > else > return lookup_template_function (tmpl, targs); > } > @@ -22097,7 +22099,7 @@ instantiate_template (tree tmpl, tree orig_args, = tsubst_flags_t complain) > /* We need to determine if we're using a partial or explicit > specialization now, because the type of the variable could be > different. */ > - tree tid =3D lookup_template_variable (tmpl, targ_ptr); > + tree tid =3D build2 (TEMPLATE_ID_EXPR, NULL_TREE, tmpl, targ_ptr); > tree elt =3D most_specialized_partial_spec (tid, complain); > if (elt =3D=3D error_mark_node) > pattern =3D error_mark_node; > diff --git a/gcc/testsuite/g++.dg/cpp/pr64127.C b/gcc/testsuite/g++.dg/cp= p/pr64127.C > index 29c3bf2662a..8dc3336a1f9 100644 > --- a/gcc/testsuite/g++.dg/cpp/pr64127.C > +++ b/gcc/testsuite/g++.dg/cpp/pr64127.C > @@ -1,4 +1,4 @@ > /* { dg-do compile { target c++98_only } } */ > > template <0> int __copy_streambufs_eof; // { dg-error "expected identifi= er|numeric constant|variable templates" } > -__copy_streambufs_eof < // { dg-error "template argument|parse error|not= name a type" } > +__copy_streambufs_eof < // { dg-error "template argument|expected unqual= ified-id" } > diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-ttp1.C b/gcc/testsuite= /g++.dg/cpp0x/alias-decl-ttp1.C > index d1af8d1bbb2..52c0362ec01 100644 > --- a/gcc/testsuite/g++.dg/cpp0x/alias-decl-ttp1.C > +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-ttp1.C > @@ -2,5 +2,5 @@ > // { dg-do compile { target c++14 } } > > template using enable_if_t =3D int; > -template bool has_P_match_v; > +template