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.133.124]) by sourceware.org (Postfix) with ESMTPS id A0FDF3858D32 for ; Thu, 1 Dec 2022 21:18:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A0FDF3858D32 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=1669929481; 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: in-reply-to:in-reply-to:references:references; bh=BGWBwVkOt6Tsn3dE2kUxm2JEGGkhGVCoP+wDO+38NMg=; b=ZL0FYAt3y5dan76BQLMcIdgIiiwQB4CMXqR3T2+9ZkbuLHOUTjcNq1zOwWkwSnojTnNcQX twRUWYm3z8KOnoeziV+TyYjAPhdMvZv0WK+2JqK+uM5SLTxM0KEDxNiP938ABWpQrwzmCq XzDPmrG/x+0ieqA6wJ16wOznCQaoU14= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-28-_ACNUtZQNqiKNnb61IF4lQ-1; Thu, 01 Dec 2022 16:17:59 -0500 X-MC-Unique: _ACNUtZQNqiKNnb61IF4lQ-1 Received: by mail-qt1-f199.google.com with SMTP id fb5-20020a05622a480500b003a525d52abcso8586350qtb.10 for ; Thu, 01 Dec 2022 13:17:59 -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:cc: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=BGWBwVkOt6Tsn3dE2kUxm2JEGGkhGVCoP+wDO+38NMg=; b=xeUxFiCNSieVuaNhF7y5P8swzKmTsjF4fhirX6l2+RH4CUER1OSmuU8bAgIiz1AgXf k3R3lFkz+PXLKsZysWQQ3+0wnNHYM0FyAhNVcR53X8b6KPA/AkwxqH8Xqg9rRaMf9PsS N4P3fCmEZrIHV6gjMP6TEwD0NH6GywIn6YuSOEvmYT+zTtctGcrsiEjgfxkeRHM0CxbY bb3MjHpmOR58PNrMk6hZbOqAcA2Zc40/sE4HK8ENSELG++ReJ0HJb3fG0+fNal4uyUIT 3w5N3RZ4GisfrQDBfPjN1h6nxkBqip2jYFo8A1n8bcvrtKzhAvdXypVE6xn7Rkis0bpp TnjQ== X-Gm-Message-State: ANoB5pkzLGuE3imEHCMPjd/aMLMcc+xn0mTpEP0Od6L2uXeo2hj68GOS 5Uj7DqJxXqtMsj8XwyPr5BI2bBONTMJhwK5k3Jv6QHU/mjSQ7lSZzx+nf/4MPvBsq5v5B8NDAr3 i2uf36q++R/wA/i/NcA== X-Received: by 2002:ad4:5768:0:b0:4bb:728e:b232 with SMTP id r8-20020ad45768000000b004bb728eb232mr25480392qvx.27.1669929478581; Thu, 01 Dec 2022 13:17:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ydCAzGZgimi1SiRIfbSZVhIB8uitJK7gd0dS4hwnlc6H3e2mDDiGcjf2KiWb/asRj1MFCLA== X-Received: by 2002:ad4:5768:0:b0:4bb:728e:b232 with SMTP id r8-20020ad45768000000b004bb728eb232mr25480367qvx.27.1669929478224; Thu, 01 Dec 2022 13:17:58 -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 k14-20020a05620a414e00b006cebda00630sm1136156qko.60.2022.12.01.13.17.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Dec 2022 13:17:57 -0800 (PST) Message-ID: <967940e9-3ed4-bcfe-20f4-73eaf38d41a4@redhat.com> Date: Thu, 1 Dec 2022 16:17:56 -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++: explicit spec of constrained member tmpl [PR107522] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20221201163752.2176490-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: 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.5 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/1/22 14:51, Patrick Palka wrote: > On Thu, 1 Dec 2022, Jason Merrill wrote: > >> On 12/1/22 11:37, Patrick Palka wrote: >>> 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. >> >> But why are they carried over? We wrote a specification of the constraints in >> terms of the template parameters of the specialization, why are we throwing >> that away? > > Using the partially instantiated constraints would require adding a > special case to satisfaction since during satisfaction we currently > always use the full set of template arguments (relative to the most > general template). But not for partial specializations, right? It seems natural to handle this explicit instantiation the way we handle partial specializations, as both have their constraints written in terms of their template parameters. > For satisfaction of the partially instantiated > constraints, we'd instead have to use the template arguments relative to > the explicit specialization, e.g. {42} instead of {{int},{42}} for > A::f<42>. Not sure if that would be preferable, but it seems > doable. > >> >>> 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" } >>> +} >> >> >