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 AD6933856271 for ; Mon, 30 May 2022 02:10:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AD6933856271 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-153-yjA9BNxiPGquOHYQ7BNXPQ-1; Sun, 29 May 2022 22:10:39 -0400 X-MC-Unique: yjA9BNxiPGquOHYQ7BNXPQ-1 Received: by mail-qv1-f69.google.com with SMTP id e3-20020a056214110300b0045abb0e1760so7391773qvs.3 for ; Sun, 29 May 2022 19:10:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=UJoGn6WZumEe1Y3YHldInPRBOyH3bHrRxyCirXFlqrk=; b=PoTeJT2Z9NGazvJ9W9tvZjGSt001VxKOLK+i3EGE4FlVZ4vLjE5APzxYd7RsY39Ujj a+nsHTm8+2JaDxorjsPq4F5N7/wfEGwBRGkDJ1j/9Qp3GGG2NeDefE2+NBbemM7UYd47 9RT1yz9jPxz2ytM+uTcxh5+T3n6GEMw4C1do84JleYk5D7UYy4r+Q5RLt/ONdwCILTc0 i2/vhLDl3tCOFLTh085x1d/BPqz3WK9X9ooYAspRAF1seVljm0UwQ2xqbjhbgUzvlQtm w8gH9/zAHF/OvxX6qeDur/RPmEN38Wqd861KxKPXDC/va5J3ew7Tc7XrSgBO1mDAeKct GZKQ== X-Gm-Message-State: AOAM533j+aAZWsIg4jrUzbqK62dyT3fvKltWbG2DPAu1loUDC6IeEyki JbsJklkH6vbEBhIUO56PAuJvLNS0i+0IwAME/CGs6xi5nQ0ZRbQ4TN2HpjOsMD+5xlH+2wuF6gO VOmhaSZWAaifbMofVRQ== X-Received: by 2002:ac8:5a82:0:b0:304:b4ff:2bca with SMTP id c2-20020ac85a82000000b00304b4ff2bcamr369557qtc.552.1653876638436; Sun, 29 May 2022 19:10:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzNa1cnOJJSYnh4B1p7j2TIs1Ue/OOJYNk1IcksMQARpWA+CfSTGkoqMB0MpthlYOsEkdSGA== X-Received: by 2002:ac8:5a82:0:b0:304:b4ff:2bca with SMTP id c2-20020ac85a82000000b00304b4ff2bcamr369546qtc.552.1653876638069; Sun, 29 May 2022 19:10:38 -0700 (PDT) Received: from [192.168.1.100] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id u16-20020a05620a121000b006a0ba4b8f48sm6903454qkj.49.2022.05.29.19.10.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 May 2022 19:10:37 -0700 (PDT) Message-ID: Date: Sun, 29 May 2022 22:10:36 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] c++: don't substitute TEMPLATE_PARM_CONSTRAINT [PR100374] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20220527180543.2908762-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20220527180543.2908762-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 May 2022 02:10:42 -0000 On 5/27/22 14:05, Patrick Palka wrote: > This makes us avoid substituting into the TEMPLATE_PARM_CONSTRAINT of > each template parameter except as necessary for (friend) declaration > matching, like we already do for the overall TEMPLATE_PARMS_CONSTRAINTS > of a template parameter list. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk and perhaps 12.2? Also tested on range-v3 and cmcstl2. Are there already tests that cover the friend cases? > PR c++/100374 > > gcc/cp/ChangeLog: > > * pt.cc (tsubst_each_template_parm_constraint): Define. > (tsubst_friend_function): Use it. > (tsubst_friend_class): Use it. > (tsubst_template_parm): Don't substitute TEMPLATE_PARM_CONSTRAINT. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/concepts-template-parm11.C: New test. > --- > gcc/cp/pt.cc | 35 ++++++++++++++++--- > .../g++.dg/cpp2a/concepts-template-parm11.C | 16 +++++++++ > 2 files changed, 47 insertions(+), 4 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-template-parm11.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 24bbe2f4060..ec168234325 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -184,6 +184,7 @@ static int unify_pack_expansion (tree, tree, tree, > tree, unification_kind_t, bool, bool); > static tree copy_template_args (tree); > static tree tsubst_template_parms (tree, tree, tsubst_flags_t); > +static void tsubst_each_template_parm_constraint (tree, tree, tsubst_flags_t); > tree most_specialized_partial_spec (tree, tsubst_flags_t); > static tree tsubst_aggr_type (tree, tree, tsubst_flags_t, tree, int); > static tree tsubst_arg_types (tree, tree, tree, tsubst_flags_t, tree); > @@ -11254,7 +11255,12 @@ tsubst_friend_function (tree decl, tree args) > tree parms = DECL_TEMPLATE_PARMS (new_friend); > tree treqs = TEMPLATE_PARMS_CONSTRAINTS (parms); > treqs = maybe_substitute_reqs_for (treqs, new_friend); > - TEMPLATE_PARMS_CONSTRAINTS (parms) = treqs; > + if (treqs != TEMPLATE_PARMS_CONSTRAINTS (parms)) > + { > + TEMPLATE_PARMS_CONSTRAINTS (parms) = treqs; > + /* As well as each TEMPLATE_PARM_CONSTRAINT. */ > + tsubst_each_template_parm_constraint (parms, args, tf_warning_or_error); > + } > } > > /* The mangled name for the NEW_FRIEND is incorrect. The function > @@ -11500,6 +11506,8 @@ tsubst_friend_class (tree friend_tmpl, tree args) > { > tree parms = tsubst_template_parms (DECL_TEMPLATE_PARMS (friend_tmpl), > args, tf_warning_or_error); > + tsubst_each_template_parm_constraint (parms, args, > + tf_warning_or_error); > location_t saved_input_location = input_location; > input_location = DECL_SOURCE_LOCATION (friend_tmpl); > tree cons = get_constraints (tmpl); > @@ -11534,6 +11542,8 @@ tsubst_friend_class (tree friend_tmpl, tree args) > DECL_FRIEND_CONTEXT (friend_tmpl)); > --processing_template_decl; > set_constraints (tmpl, ci); > + tsubst_each_template_parm_constraint (DECL_TEMPLATE_PARMS (tmpl), > + args, tf_warning_or_error); > } > > /* Inject this template into the enclosing namspace scope. */ > @@ -13656,7 +13666,6 @@ tsubst_template_parm (tree t, tree args, tsubst_flags_t complain) > > default_value = TREE_PURPOSE (t); > parm_decl = TREE_VALUE (t); > - tree constraint = TEMPLATE_PARM_CONSTRAINTS (t); > > parm_decl = tsubst (parm_decl, args, complain, NULL_TREE); > if (TREE_CODE (parm_decl) == PARM_DECL > @@ -13664,13 +13673,31 @@ tsubst_template_parm (tree t, tree args, tsubst_flags_t complain) > parm_decl = error_mark_node; > default_value = tsubst_template_arg (default_value, args, > complain, NULL_TREE); > - constraint = tsubst_constraint (constraint, args, complain, NULL_TREE); > > tree r = build_tree_list (default_value, parm_decl); > - TEMPLATE_PARM_CONSTRAINTS (r) = constraint; > + TEMPLATE_PARM_CONSTRAINTS (r) = TEMPLATE_PARM_CONSTRAINTS (t); > return r; > } > > +/* Substitute in-place the TEMPLATE_PARM_CONSTRAINT of each template > + parameter in PARMS for sake of declaration matching. */ > + > +static void > +tsubst_each_template_parm_constraint (tree parms, tree args, > + tsubst_flags_t complain) > +{ > + ++processing_template_decl; > + for (; parms; parms = TREE_CHAIN (parms)) > + { > + tree level = TREE_VALUE (parms); > + for (tree parm : tree_vec_range (level)) > + TEMPLATE_PARM_CONSTRAINTS (parm) > + = tsubst_constraint (TEMPLATE_PARM_CONSTRAINTS (parm), args, > + complain, NULL_TREE); > + } > + --processing_template_decl; > +} > + > /* Substitute the ARGS into the indicated aggregate (or enumeration) > type T. If T is not an aggregate or enumeration type, it is > handled as if by tsubst. IN_DECL is as for tsubst. If > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-template-parm11.C b/gcc/testsuite/g++.dg/cpp2a/concepts-template-parm11.C > new file mode 100644 > index 00000000000..f70de341a07 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-template-parm11.C > @@ -0,0 +1,16 @@ > +// PR c++/100374 > +// { dg-do compile { target c++20 } } > + > +template > +concept C = true; > + > +template > +struct A { > + template U> > + void f(); > + > + template U> > + struct B; > +}; > + > +template struct A;