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 A19C73858417 for ; Fri, 2 Dec 2022 14:30:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A19C73858417 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=1669991442; 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: in-reply-to:in-reply-to:references:references; bh=DzjGqPmPKFJvBiyx9iGlTtaGtGlNBpK3zUwn3McEzEY=; b=MWdOTeaKmT1BJ1Wx53Hgm8gE2HD7VxSY85DfsXtxnmYfTd+amBdB25ghOHgelXgGqyboFh FoinLMv9B/k/NClHITgLRnDVZxASUIPOoMRhFBxrGVy2c7Gbgbn/l9jqzexiGxOFN4Z83d jXGmqQPrmYnwL6PwUrg2Je4GktE9SNY= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-96-R-mQec0DP3WEPDbOh8CSMQ-1; Fri, 02 Dec 2022 09:30:40 -0500 X-MC-Unique: R-mQec0DP3WEPDbOh8CSMQ-1 Received: by mail-qt1-f198.google.com with SMTP id n12-20020ac85a0c000000b003a5849497f9so18722037qta.20 for ; Fri, 02 Dec 2022 06:30:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DzjGqPmPKFJvBiyx9iGlTtaGtGlNBpK3zUwn3McEzEY=; b=LwqD3dFLrDFoxcD2vYZowlUZ9dbxWLYx/vavT2WFjYS40NfytHgKjs7KxBbAmg3llm 3VhWjapnxnyihdbukrCC1RQUYuZUKUB+oWFPyI/AIDpT//FEbw7QBsJbcpSNgAaLTT6s pT6JFU4gvjqcUv7q4FtoeOgo4WxFd43GZXFcmEQFJUwCnVbKWDbvRsRglXnpjTtBF//b axZLbOY95uK6vp64Z50lj363onsyGQ8yMFyvJam+C6mlO/bam7ai5sM/jGoBzIg94Gpj xDFXiklIvinyNn4EwCjLhnyk+QnVuDsPLMml9/Y7v4O+V1gZLf/DuTEc2Br/CtJmcOIC Z7cw== X-Gm-Message-State: ANoB5pk/G7TmbR4VqzPsKcRD1WByY8+SvZqGPpFaeLc7OCETl1ZoBXoN bqykp9N74B5dA2f3HPBUK9SUBcCDcnY99/Kj3yTuVhaMBNfYOH/AdPTrRZ8zebyNZCyy4Dvni2a 98mNo31u0pxhD/zN4mA== X-Received: by 2002:a05:622a:1f8b:b0:3a5:1fa1:4b7e with SMTP id cb11-20020a05622a1f8b00b003a51fa14b7emr66073593qtb.161.1669991440087; Fri, 02 Dec 2022 06:30:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf7iW7Rj5v5XHcX76J7E8fqzNVYXyxitfA/jRlSTHQii52+tATz30tXuLVQk3ZaR9AGNpILsJQ== X-Received: by 2002:a05:622a:1f8b:b0:3a5:1fa1:4b7e with SMTP id cb11-20020a05622a1f8b00b003a51fa14b7emr66073556qtb.161.1669991439708; Fri, 02 Dec 2022 06:30:39 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id i11-20020a05620a248b00b006ee949b8051sm5754600qkn.51.2022.12.02.06.30.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 06:30:39 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Fri, 2 Dec 2022 09:30:38 -0500 (EST) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: explicit spec of constrained member tmpl [PR107522] In-Reply-To: <967940e9-3ed4-bcfe-20f4-73eaf38d41a4@redhat.com> Message-ID: References: <20221201163752.2176490-1-ppalka@redhat.com> <967940e9-3ed4-bcfe-20f4-73eaf38d41a4@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.9 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: On Thu, 1 Dec 2022, Jason Merrill wrote: > 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. True, but what about the general rule that we don't partially instantiate constraints outside of declaration matching? Checking satisfaction of partially instantiated constraints here can introduce hard errors during normalization, e.g. template concept C1 = __same_as(T, void); template concept C2 = C1; template concept D = (N == 42); template struct A { template static void f() requires C2 || D; }; template<> template void A::f() requires C2 || D { } int main() { A::f<42>(); } Normalization of the the partially instantiated constraints will give a hard error due to 'int::type' being ill-formed, whereas the uninstantiated constraints are fine. > > > 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" } > > > > +} > > > > > > > > > >