From patchwork Thu Dec 1 16:37:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 28454 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp362355wrr; Thu, 1 Dec 2022 08:38:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf6WcGiyxM+zCQVD09mYzpiPydq07kg07dTe03ggyMaulmVw7LPDnu6eknST+IauvtawJo88 X-Received: by 2002:a17:906:9718:b0:7bf:1090:ded6 with SMTP id k24-20020a170906971800b007bf1090ded6mr18587817ejx.577.1669912724216; Thu, 01 Dec 2022 08:38:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669912724; cv=none; d=google.com; s=arc-20160816; b=fhFWiOjqhao8Pn+hUcxA1TVJbgLoI43cEk1O75L/yK1YdZ3Xh5Mn50Q98iUqFEgBQb clUNtOjbL7rKWnpJiCUr4JEUYjRnikhyRfhaFArIfdd/DVonePnexkVH78MifRqHpbKH K1v6j3qmiEjCjuYQp6IKsl//6of/4lU6O7TJR9C5rIyQ97MeMHs5gVvj4OFninMYPSJJ 39m0BUDI1pq4wuwJ3oin8ss3yTquDdTiOM94TvNUgWQ4fthT/WfZnG3dy/uD2rc2Iw59 1WXx5mswQyFW4B1zbV9k5urmivX67UiAJ7aydIKqygZXHM0Q3um2BXyXYybdU7IBiruT V0Ew== 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=it14fpxQjcR23b4X0DB8NvmvqI8vzOAIExG3ekvEKT4=; b=HV9xbA+KYzJlv56sczmjtN9QYjCNxjAsJrn4UZ1Hqd4PtGvp+apwS49KjgHjLt4yei kOARftCyiMvlnwe9CJYMyv5bPK7h1085wiKDqmBrbvmFVciKiBit/fUMdTIT6sDk6ruD UOq/Y1FKG4ULoiDpzwA7lAsbX6n3TkuMjQqCoXJGUDx7WvJ28m2sypvDybwD9McogBCA ZcwwVx2HX9BVf362NJcIwEMP4+uSa3ILeRmmFG0qfed/1WsxfbUbcTd+K3Hw+lnemUej 9xK5yPD6Nrlwvbr8yjdRKhDZSaSk5JeJVGOErYRmgOSAyFjJDREzpU93R1VWX+tF+bSH EjrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=s2wAz4vJ; 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 sg12-20020a170907a40c00b007918f58458bsi4301672ejc.441.2022.12.01.08.38.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 08:38:44 -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=s2wAz4vJ; 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 055873858433 for ; Thu, 1 Dec 2022 16:38:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 055873858433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669912723; bh=it14fpxQjcR23b4X0DB8NvmvqI8vzOAIExG3ekvEKT4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=s2wAz4vJW0v69tcrzGgm+AvFIZQ/iFEyZJBJyFl3xxo0ght1z7jf7YleaEe4VGWV0 ud1IHazqqk62xv9eWITu3s9yOBnG1lOmSL/EmCLY9L22gmfFElnzw4UJzJYObZYMaX SpxWpA8f+WVUyA31+UccPl1kKW8TMrl7ekdZhxmM= 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 E42A53858D32 for ; Thu, 1 Dec 2022 16:37:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E42A53858D32 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-433-bVcXYSFCNWaOAQ4AovXuow-1; Thu, 01 Dec 2022 11:37:57 -0500 X-MC-Unique: bVcXYSFCNWaOAQ4AovXuow-1 Received: by mail-qv1-f70.google.com with SMTP id q17-20020a056214019100b004b1d3c9f3acso5941973qvr.0 for ; Thu, 01 Dec 2022 08:37:57 -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=it14fpxQjcR23b4X0DB8NvmvqI8vzOAIExG3ekvEKT4=; b=4QzL+KVxmLG2c9Endqn7h/R8+PZjU+ewRykRga9YIS8vG8pU2l0zrgBbcyZOdthNLu VjEsY/CklpxUNmL9WHAgsehgvEHc7pCua59YGKX34e4ylKd+Pb94wODNriMEneNawOQj gVU7P7U0c9KJq4/wsrbZVoXQ+w93mxNfXfAg5pxTHl5AcOR5azFdk3DG1cHkIvbI3wYA 7S5RadKHmFz9lS+nTi8p+dYvjfVhsGsmKv1d8jb+2+frK6+Q6WXU72k/EiszOLolg9lE cJP0Rjd8SWaED8LHvia8Afj29gJ3T5qjSlEGaEWtV6Psf48IhPTr0/uBNDx0OBqNDTNB 9EIQ== X-Gm-Message-State: ANoB5plcc4wMmi+TQxxlGNoxD6jusemB/+zrYqhf6WPcZISQjVFcAQVs aHCg/aDURLmCFgQSC7Zh23XLByQ4+VlXh2oXhBWqhRHpPsgBCMxvPilS36yFyqVx+xkfnYcYh0a iZgz7TIhGpp8cIDz4+xKbsT+kJodfJEg9OXtiplPCxXhNXZJAjzhvCST5WDFyeVs6bZk= X-Received: by 2002:a05:620a:128f:b0:6fc:2d7a:c3ed with SMTP id w15-20020a05620a128f00b006fc2d7ac3edmr35763578qki.649.1669912676387; Thu, 01 Dec 2022 08:37:56 -0800 (PST) X-Received: by 2002:a05:620a:128f:b0:6fc:2d7a:c3ed with SMTP id w15-20020a05620a128f00b006fc2d7ac3edmr35763545qki.649.1669912675987; Thu, 01 Dec 2022 08:37:55 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id h12-20020ac8714c000000b0039a372fbaa5sm2742365qtp.69.2022.12.01.08.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 08:37:55 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: explicit spec of constrained member tmpl [PR107522] Date: Thu, 1 Dec 2022 11:37:52 -0500 Message-Id: <20221201163752.2176490-1-ppalka@redhat.com> X-Mailer: git-send-email 2.39.0.rc0.49.g083e01275b 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?1751030404716854721?= X-GMAIL-MSGID: =?utf-8?q?1751030404716854721?= When defining a explicit specialization of a constrained member template (of a class template) such as f and g in the below testcase, the DECL_TEMPLATE_PARMS of the corresponding TEMPLATE_DECL are partially instantiated, whereas its associated constraints are carried over from the original template and thus are in terms of the original DECL_TEMPLATE_PARMS. So during normalization for such an explicit specialization we need to consider the (parameters of) the most general template, since that's what the constraints are in terms of and since we always use the full set of template arguments during satisfaction. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk and perhaps 12? PR c++/107522 gcc/cp/ChangeLog: * constraint.cc (get_normalized_constraints_from_decl): Use the most general template for an explicit specialization of a member template. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-explicit-spec7.C: New test. --- gcc/cp/constraint.cc | 18 ++++++++--- .../g++.dg/cpp2a/concepts-explicit-spec7.C | 31 +++++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-explicit-spec7.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index ab0f66b3d7e..f1df84c2a1c 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -973,11 +973,19 @@ get_normalized_constraints_from_decl (tree d, bool diag = false) accepting the latter causes the template parameter level of U to be reduced in a way that makes it overly difficult substitute concrete arguments (i.e., eventually {int, int} during satisfaction. */ - if (tmpl) - { - if (DECL_LANG_SPECIFIC(tmpl) && !DECL_TEMPLATE_SPECIALIZATION (tmpl)) - tmpl = most_general_template (tmpl); - } + if (tmpl && DECL_LANG_SPECIFIC (tmpl) + && (!DECL_TEMPLATE_SPECIALIZATION (tmpl) + /* DECL_TEMPLATE_SPECIALIZATION means we're dealing with either a + partial specialization or an explicit specialization of a member + template. In the former case all is well: the constraints are in + terms in TMPL's parameters. But in the latter case TMPL's + parameters are partially instantiated whereas its constraints + aren't, so we need to consider (the parameters of) the most + general template. The following test distinguishes between a + partial specialization and such an explicit specialization. */ + || (TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (tmpl)) + < TMPL_ARGS_DEPTH (DECL_TI_ARGS (tmpl))))) + tmpl = most_general_template (tmpl); d = tmpl ? tmpl : decl; diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-explicit-spec7.C b/gcc/testsuite/g++.dg/cpp2a/concepts-explicit-spec7.C new file mode 100644 index 00000000000..5b5a6df20ff --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-explicit-spec7.C @@ -0,0 +1,31 @@ +// PR c++/107522 +// { dg-do compile { target c++20 } } + +template +struct A +{ + template + static void f() requires (N == 42); + + template + struct B { + template + static void g() requires (T(N) == 42); + }; +}; + +template<> +template +void A::f() requires (N == 42) { } + +template<> +template<> +template +void A::B::g() requires (int(N) == 42) { } + +int main() { + A::f<42>(); + A::f<43>(); // { dg-error "no match" } + A::B::g<42>(); + A::B::g<43>(); // { dg-error "no match" } +}