From patchwork Mon Dec 12 17:20:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 32463 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2365286wrr; Mon, 12 Dec 2022 09:21:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf6z1tafepr/h+4jGHKsOgUvHi2H6oH/8zIw+OdfxCWb8GERY9UIFuhaf31G8UBPkZOTbc7m X-Received: by 2002:a17:906:ecb7:b0:7c1:f6c:dd4e with SMTP id qh23-20020a170906ecb700b007c10f6cdd4emr16188319ejb.40.1670865713351; Mon, 12 Dec 2022 09:21:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670865713; cv=none; d=google.com; s=arc-20160816; b=1AdYoQwQxb1AMvwseijv4mxGi+marvgPVS7uGNEk3dR1F/yHlNU5MzZ3t7KOM6PlTd MrcSfIwVjhvw3/v8tUxsgkdBZqXrjH8r4dtmRr1yTsvsAaU+6u9UHwx29oTeb+KJHbqP PwXIbiQGdcpMnQ8tkUKkL+TJyIg8HitRc+Y2NQT0eAvPNsFJSOUFyVqCC5hNnUF1SrNN 3xa381OcVtDMGGgJohVlZZI/Dq9v5fipqc5+hrnGnLuMni6ZxzVJaIvhzqeG0q/iQZMk UMjbd3avJ7HlBCCpoEpI4B+rN1/o/m/wEX0/ZegV09RlCM0Uc109mZk5K+a7d8bCdxzN wXKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=pvS50S9pscAyUsuaMuKpjFnx2wjqEiC2Tt5Rpi7plzU=; b=g1tjYHRi0DKHxUfbM4DE8BhL/H1JcS1Zyo7KPNAxOo+y3+LRufb5NepQYgY1dZkrf8 BHUEJjuRhkUbpo8qxA2b5RSu3NwWRmygDQpmpTJet31lyIMqvq06KUAmFALGS4qzHts9 f/+dP8WNqdYE3DN0mWhQbN6tnsGi/iZpefr6MF18rRfL0yjbl+xTVSC0XS7NZO/n0Qkx 3oYdHhS1c3+G9+RQ2g63SFrZw3t4VrrTVYh8qDNiqog2gd0AdLyb6qMbLlnQPoORi8qm mk7Pk0D7gtPyDILcjCs3oXgXXxBju5wMH8Ui+I/OT+IOAwnWnaoilPexolpNLMZgth88 HDkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="S/5P85Nu"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f17-20020a170906825100b0078049ab4bbasi4911166ejx.526.2022.12.12.09.21.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 09:21:53 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="S/5P85Nu"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 58F21385061C for ; Mon, 12 Dec 2022 17:21:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58F21385061C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670865712; bh=pvS50S9pscAyUsuaMuKpjFnx2wjqEiC2Tt5Rpi7plzU=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=S/5P85NuY/Ac71RAOSy3bbC67VmUPg5tcBM1xTWj0IrvlmrukLmCbjtxqWbm2bywZ QKexyrjzkudW/QvqEZnZCyv5qgjohwk9XMHgc4RsOKzHjMgvVavr88+tVpx899SqAr v50JPTso61Go9Igj0XQ/k2zC2Wy9Lr+LxYqbPcgo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 5C5D9386102D for ; Mon, 12 Dec 2022 17:21:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5C5D9386102D Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-279-zr8AhNk8NAWD75QSZLOmGA-1; Mon, 12 Dec 2022 12:21:01 -0500 X-MC-Unique: zr8AhNk8NAWD75QSZLOmGA-1 Received: by mail-qk1-f200.google.com with SMTP id x2-20020a05620a448200b006fa7dad5c1cso14620711qkp.10 for ; Mon, 12 Dec 2022 09:21:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pvS50S9pscAyUsuaMuKpjFnx2wjqEiC2Tt5Rpi7plzU=; b=oUZuxY+btwZClAw5PZiiA3KK3wdVZvURq81Ei5wV8hRCAVj2nFYCNTJjEYa102eTWH ZYt6xHI1/yZoFN7i1a6TSqVAI6qOykSC4YlySFEdgp8+Hto9ZTp7hhI4i1fDYLY3u0Bc 8fHTMnIkedYLTmLuoe0exuzhUtBiFt7WdCd+qLp/uguCI2iUj88JJED18cHNF/ujRBP2 IOQcNGzF1GlBUkBuuqhY03AJpEYHAnUXrJMTruYXQ9P2evXv70ERR8Dr2m9HSrPbryvg PPRqgt2xRc1CRaLjiIrW+FNvdJMc+DQDYjpUheyXdeJJoBQgpQViIlHxaDWJnPcg+tdc UKJw== X-Gm-Message-State: ANoB5pkXNHXCmBQMAdJ6Sm6NmfVIcZI9UO3kGFIq9NJbnvAkM+aVE6Oc B/XQRt4362eNgsUfRnP2G3/ViNQkdmm7yjEJCaT8LURnYm3fJX4eGPO1uR+bh1Nm2UAqNsm566E k1N7cZbLCWjBwZiO3zzN20QH1Pd22hbJfmQeXWsF/6bb4QOAKQWk/E6oVVoW0mkLZ7Cg= X-Received: by 2002:a05:622a:1e11:b0:3a5:fa33:917f with SMTP id br17-20020a05622a1e1100b003a5fa33917fmr25124980qtb.37.1670865660389; Mon, 12 Dec 2022 09:21:00 -0800 (PST) X-Received: by 2002:a05:622a:1e11:b0:3a5:fa33:917f with SMTP id br17-20020a05622a1e1100b003a5fa33917fmr25124952qtb.37.1670865660030; Mon, 12 Dec 2022 09:21:00 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id 3-20020ac85643000000b003a816011d51sm1911685qtt.38.2022.12.12.09.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 09:20:59 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: template friend with variadic constraints [PR108066] Date: Mon, 12 Dec 2022 12:20:57 -0500 Message-Id: <20221212172057.3527670-1-ppalka@redhat.com> X-Mailer: git-send-email 2.39.0.rc2.23.g694cb1b2ab MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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, 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 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-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752029686483723734?= X-GMAIL-MSGID: =?utf-8?q?1752029686483723734?= When instantiating a constrained hidden template friend, we need to substitute into its constraints for sake of declaration matching. 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. 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. 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); + } 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" } +}