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 6E7183858D35 for ; Thu, 1 Dec 2022 19:15:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E7183858D35 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=1669922149; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DfIMvwwXJQORNNttD8hTKgFjUq0ZgvRDKUHiEUpzVYw=; b=Z4gliow10N6fRmgo3V0E3GufzS4AaHVB+2Lb86+tvsHMembtwoRcjFbJUSpsRFqTRG6/C6 dAavCDaIrqaL9EVZziOT0zpSk+g2uPY6tft0PuFKDRXj0v0m9vfawga5fbxk1BlMlki0R3 CusTKqcpew3OZ8iRsm1qDADqn0iIT5M= 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-223-Ibtqkf_hOzSHkv9i0LkDDw-1; Thu, 01 Dec 2022 14:15:48 -0500 X-MC-Unique: Ibtqkf_hOzSHkv9i0LkDDw-1 Received: by mail-qv1-f70.google.com with SMTP id mi12-20020a056214558c00b004bb63393567so7775263qvb.21 for ; Thu, 01 Dec 2022 11:15:47 -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: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=DfIMvwwXJQORNNttD8hTKgFjUq0ZgvRDKUHiEUpzVYw=; b=ieYzZWWm9m3ychPLmoVCVQfxPFAktKOM2rrNx2SMohZ3xd8PJoquk+H3sXUzo/rMvs D44dv+svGPSf0uEzhL8SSQ4hyi+NIx/85Ozai03TJT+Hq92N/NXI3ELfYHM++jBzBQpQ Xnh7B7FTRmzn+AAJl2BGVPzQeC+hHXRueaQaYlSMzjnagfYKMKKKKZkIzCYvOIO4WD9H 306m+T7Fl/wNx1/8o4B7vAjO1MlxqghrMw/4YL05Dx/tHQ5mdJwt5zKUYQjgshHL1Vsb 0BkqoyDfnT9xTL/veg24jVGypy3uIdjZWXkVyJdRaXCzmQ/dKMtSP5WVHH/Uqxhc4Q8w U/sA== X-Gm-Message-State: ANoB5plPCkNt1D/e9MP82R+wp4Kuhya039SkV13pXuaxFTM6Lz7dUNZc clC20L/FCT9to1ccg7pfUuSTPp4aE1eL2GRdCVFhkl87hXSDSs30aVFy6N2fPMcNC2JMKhVVlN5 cJaQRRgeapcPO6F4Ytg== X-Received: by 2002:a05:620a:4708:b0:6fa:ada7:e51b with SMTP id bs8-20020a05620a470800b006faada7e51bmr46493518qkb.674.1669922147457; Thu, 01 Dec 2022 11:15:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf5DN/GzR7QO377vIZMaCs8pEJv2A7A+8OUU1Dpw8iWxlZIqbD++nOX275iYWB1ENuwDQ5+TSw== X-Received: by 2002:a05:620a:4708:b0:6fa:ada7:e51b with SMTP id bs8-20020a05620a470800b006faada7e51bmr46493492qkb.674.1669922147156; Thu, 01 Dec 2022 11:15:47 -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 s3-20020ac85283000000b003a4cda52c95sm2953466qtn.63.2022.12.01.11.15.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Dec 2022 11:15:46 -0800 (PST) Message-ID: Date: Thu, 1 Dec 2022 14:15:45 -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 , gcc-patches@gcc.gnu.org References: <20221201163752.2176490-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20221201163752.2176490-1-ppalka@redhat.com> 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 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 temprate parameters of the specialization, why are we throwing that away? > 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" } > +}