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 0FE213898388 for ; Thu, 15 Dec 2022 16:22:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0FE213898388 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=1671121350; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=95WaVO5AblU/vrvocokZY3GvxBfQLOkD5zd7DCsk0eg=; b=jCniNbAGJH/aFpt2Btg32Offft094Jta5lwXMWLn7JnJq0TllH+45aXg9UILyOucbWoc7v bPkA28QkuLCFRC90+Zhlc609bo99AA4xMow6Ko8RWPERZT3cMZwFWhwMVXp0FsjTdFLEsT TIKr1pH0lQLbM77lJ9nSokAL0qIF4+Q= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-133-d1BGoy4tO9y0fFXQDecdTw-1; Thu, 15 Dec 2022 11:22:29 -0500 X-MC-Unique: d1BGoy4tO9y0fFXQDecdTw-1 Received: by mail-qv1-f70.google.com with SMTP id y11-20020ad457cb000000b004c6fafdde42so2314387qvx.5 for ; Thu, 15 Dec 2022 08:22:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=95WaVO5AblU/vrvocokZY3GvxBfQLOkD5zd7DCsk0eg=; b=u78n1spmjqbFlBDZnCgxg7k2v21NNAx596TDmHk/LxYWLprj88IYBQCVekzhq9FR1B Et8IeX09JCs1lw22gPnVvNcDX9T/ori5r9EziR5mCbcfB+P/2oJn6G9zzQu41DY23JI7 donzTwRnAJ8zK6l/L3R7JgeNlepBh6jS10OURPV96ScW3wRRxcPaRW+DZYxI5kLACRJt Uhfs9gjvOZmo6oJNR2oDqhQtRdyfWX0wvD4/pOGaMryHERzDzSfHhv8z+kBcKGyg8Wdj v3dcXTbBpPhWT9K1NjkJdzv00iecVZ573W7MFudoT3FVzRhSUgJnKIrgwX/LFddHOcQj DN/Q== X-Gm-Message-State: ANoB5pnvJYvR/zIZDbh+xjp55v8m7JPBRKtm6eEqYGGge94c6Xcihl4H dpzc7evv8FoaxajydYYfToeZblRRUcttyxjirZ8gAM9/29fZDWQmLPWvTKnH6t/1JKXf+BOQGIq lxdm1DFxVBngmtTbs7A== X-Received: by 2002:a05:622a:4c0a:b0:3a8:26b1:336a with SMTP id ey10-20020a05622a4c0a00b003a826b1336amr15143751qtb.17.1671121348891; Thu, 15 Dec 2022 08:22:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf4w3h20bBDFu5zKO4zq7bw06JX0+8BwcOLdQ1f5y2NYzLvDo88sec886O27NCTrOfuLvu3pNg== X-Received: by 2002:a05:622a:4c0a:b0:3a8:26b1:336a with SMTP id ey10-20020a05622a4c0a00b003a826b1336amr15143718qtb.17.1671121348534; Thu, 15 Dec 2022 08:22:28 -0800 (PST) Received: from [192.168.1.108] (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 bb21-20020a05622a1b1500b003999d25e772sm3671479qtb.71.2022.12.15.08.22.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Dec 2022 08:22:27 -0800 (PST) Message-ID: <0b5ba723-31cd-b12c-e3df-c25a1d074825@redhat.com> Date: Thu, 15 Dec 2022 11:22:27 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH] c++: template friend with variadic constraints [PR108066] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20221212172057.3527670-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20221212172057.3527670-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=-12.4 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,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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 12/12/22 12:20, Patrick Palka wrote: > When instantiating a constrained hidden template friend, we need to > substitute into its constraints for sake of declaration matching. Hmm, we shouldn't need to do declaration matching when there's only a single declaration. > For > this substitution we use a full argument vector whose outer levels > correspond to the class's arguments and innermost level corresponds to > the template's level-lowered generic arguments. > > But for A::f here, for which the relevant argument vector is > {{int}, {Us...}}, this substitution triggers the assert in > use_pack_expansion_extra_args_p since one argument is a pack expansion > and the other isn't. > > And for A::f, for which the relevant argument vector is > {{int, int}, {Us...}}, the use_pack_expansion_extra_args_p assert would > also trigger but we first get a bogus "mismatched argument pack lengths" > error from tsubst_pack_expansion. > > These might ultimately be bugs in tsubst_pack_expansion, but it seems > we can work around them by tweaking the constraint substitution in > maybe_substitute_reqs_for to only use the friend's outer arguments in > the case of a template friend. Yes, this is how we normally substitute a member template during class instantiation: with the class' template args, not its own. The assert seems to be enforcing that. > This should be otherwise equivalent to > substituting using the full arguments, since the template's innermost > arguments are just its generic arguments with level=1. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk/12? > > PR c++/108066 > PR c++/108067 > > gcc/cp/ChangeLog: > > * constraint.cc (maybe_substitute_reqs_for): For a template > friend, substitute using only its outer arguments. Remove > dead uses_template_parms test. I don't see any removal? > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/concepts-friend12.C: New test. > --- > gcc/cp/constraint.cc | 8 +++++++ > .../g++.dg/cpp2a/concepts-friend12.C | 22 +++++++++++++++++++ > 2 files changed, 30 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-friend12.C > > diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc > index d4cd92ec3b4..f9d1009c9fe 100644 > --- a/gcc/cp/constraint.cc > +++ b/gcc/cp/constraint.cc > @@ -1352,6 +1352,14 @@ maybe_substitute_reqs_for (tree reqs, const_tree decl) > tree tmpl = DECL_TI_TEMPLATE (decl); > tree gargs = generic_targs_for (tmpl); > processing_template_decl_sentinel s; > + if (PRIMARY_TEMPLATE_P (tmpl)) > + { > + if (TEMPLATE_ARGS_DEPTH (gargs) == 1) > + return reqs; > + ++processing_template_decl; > + gargs = copy_node (gargs); > + --TREE_VEC_LENGTH (gargs); Maybe instead of messing with TEMPLATE_ARGS_DEPTH we want to grab the targs for DECL_FRIEND_CONTEXT instead of decl itself? > + } > if (uses_template_parms (gargs)) > ++processing_template_decl; > reqs = tsubst_constraint (reqs, gargs, > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-friend12.C b/gcc/testsuite/g++.dg/cpp2a/concepts-friend12.C > new file mode 100644 > index 00000000000..95973842afb > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-friend12.C > @@ -0,0 +1,22 @@ > +// PR c++/108066 > +// PR c++/108067 > +// { dg-do compile { target c++20 } } > + > +template > +concept C = __is_same(T, U); > + > +template > +struct A { > + template > + requires (... && C) > + friend void f(A, A) { } > +}; > + > +int main() { > + A x; > + f(x, x); > + A y; > + f(y, y); > + A z; > + f(x, z); // { dg-error "no match" } > +}