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 E42A53858D32 for ; Thu, 1 Dec 2022 16:37:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E42A53858D32 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=1669912678; 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; bh=it14fpxQjcR23b4X0DB8NvmvqI8vzOAIExG3ekvEKT4=; b=Z3wMXf+pYcyZTJQR2dg5OQ1foTu9J5gW0SLXykDw73xhrzA24WE+iQiGo/NfuHztgZYQwU xHQ6CRrXu6GVlelXQB0ayrGt3Xf0vTMf+cTprTHnvsDTW/guVnBmPdEJWzv6R2tSDwntVf w6FZAWD3Oc24RGftaH8rCoK4w94IdH4= 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-Google-Smtp-Source: AA0mqf7eKTnwSYT34wDW/AZzZI+wW+9paqek0uCI/3o5EmdTyagIHSrGH/eAjIrf2+1glSsHHb8v0Q== 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) From: Patrick Palka 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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" } +} -- 2.39.0.rc0.49.g083e01275b