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 A5FF83858D32 for ; Thu, 10 Aug 2023 21:16:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A5FF83858D32 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=1691702197; 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=b7mLIJPUjv217/GZWg6lJacur/kVEuId1BaFvxSj/D4=; b=TWImjFb0Dn0tcPgGFa+xKt3ZRHk/yECEf7Vfcz66riqrEAPnugUR5Dwp9DSr7WZCs+no8x WWEpt48D625nx4g6x38rHda1LR6OhLIbERhudFCife7AeFXy+n5havOZGz3F1UxGuQCi0B trB+7DnjoPAKL+mdNTgfD2JTAl8iosw= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-347-rz_N3rrzNuiyzznuLxC8qg-1; Thu, 10 Aug 2023 17:16:35 -0400 X-MC-Unique: rz_N3rrzNuiyzznuLxC8qg-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-76cf0c77d07so188010885a.0 for ; Thu, 10 Aug 2023 14:16:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691702194; x=1692306994; 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=b7mLIJPUjv217/GZWg6lJacur/kVEuId1BaFvxSj/D4=; b=MChOh/qWrf7suJlrzOOtGWlSuZBl70t6gSdnLyCeYxf1r3kJSEn8JiNP8oRLb8KhWz +j7VRj7/z3vTHr8tWw9rObCWNMnfWu5XVl2eNkg0xs6aLKdQLgaG5jfz0LXUFnpbs/3Q YXVGJ0DNt+62L0lJJXLid9E7xBpOuUlPKGLwf2+lHhoDoqcqXZFm2CVJnEGE8ib4BibX z7IUz3FcEP+jozZik345a3qFaanjG7Ab0eVX7wF6XDuXsVPhoTlUr7z89g56Nm4r37rC uHhNEwySXunc826avOBzA2u7aq91hqfQrTxmDt99n4BH04SoIabZLOJjJEZvdv6kH28q cMQA== X-Gm-Message-State: AOJu0YxbLOb6NQ3EdZr9AkPSzLFeZCZMN7jbmK0s639wAbFgRPy5hzcv XNfy5nn04u1/kTNDftCw44gwNIR05htRncMgvDpz2Nfk2GAXKKY5CMcBvqWDqtE3aZjg2O+LnbS WyfEdp5hZFOwPtvep3Q== X-Received: by 2002:a05:620a:818:b0:76c:c636:4796 with SMTP id s24-20020a05620a081800b0076cc6364796mr3304923qks.32.1691702194740; Thu, 10 Aug 2023 14:16:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHyTz3+yeM9dQ+ilyKUXkWimI7bFVdAUQCwowU6UHCJPHxNupAtR+7G5ymDmT1FJbAEgiUg7g== X-Received: by 2002:a05:620a:818:b0:76c:c636:4796 with SMTP id s24-20020a05620a081800b0076cc6364796mr3304914qks.32.1691702194450; Thu, 10 Aug 2023 14:16:34 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id c5-20020a05620a134500b0076c89639526sm754950qkl.93.2023.08.10.14.16.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Aug 2023 14:16:33 -0700 (PDT) Message-ID: Date: Thu, 10 Aug 2023 17:16:33 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] c++: recognize in-class var tmpl partial spec [PR71954] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20230810160842.1513222-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20230810160842.1513222-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=-13.6 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_H4,RCVD_IN_MSPIKE_WL,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 8/10/23 12:08, Patrick Palka wrote: > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK > for trunk? OK. > -- >8 -- > > This makes us recognize variable template partial specializations > defined directly inside the class body. It seems to suffice to call > check_explicit_specialization when we see a static TEMPLATE_ID_EXPR data > member, which sets SET_DECL_TEMPLATE_SPECIALIZATION and which we > otherwise don't call (for out-of-class partial specializations we call > it from from grokvardecl which is used only for out-of-class definitions). > We also need to make finish_member_template_decl return NULL_TREE for > such partial specializations (matching its behavior class template > partial specializations) so that its caller doesn't try to call > finish_member_declaration on it. > > PR c++/71954 > > gcc/cp/ChangeLog: > > * decl.cc (grokdeclarator): Use 'dname' instead of > 'unqualified_id' when building the VAR_DECL for a static data > member. Call check_explicit_specialization for a > TEMPLATE_ID_EXPR such member. > * pt.cc (finish_member_template_decl): Return NULL_TREE > instead of 'decl' when DECL_TEMPLATE_SPECIALIZATION is not > set. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp1y/var-templ84.C: New test. > * g++.dg/cpp1y/var-templ84a.C: New test. > --- > gcc/cp/decl.cc | 11 ++++++++++- > gcc/cp/pt.cc | 2 +- > gcc/testsuite/g++.dg/cpp1y/var-templ84.C | 12 ++++++++++++ > gcc/testsuite/g++.dg/cpp1y/var-templ84a.C | 19 +++++++++++++++++++ > 4 files changed, 42 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ84.C > create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ84a.C > > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > index 9fe3a0b98fd..2b3fb313166 100644 > --- a/gcc/cp/decl.cc > +++ b/gcc/cp/decl.cc > @@ -14440,7 +14440,16 @@ grokdeclarator (const cp_declarator *declarator, > /* C++ allows static class members. All other work > for this is done by grokfield. */ > decl = build_lang_decl_loc (id_loc, VAR_DECL, > - unqualified_id, type); > + dname, type); > + if (unqualified_id > + && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR) > + { > + decl = check_explicit_specialization (unqualified_id, decl, > + template_count, > + concept_p * 8); > + if (decl == error_mark_node) > + return error_mark_node; > + } > set_linkage_for_static_data_member (decl); > if (concept_p) > error_at (declspecs->locations[ds_concept], > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 2706fa619bf..a4809f034dc 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -314,7 +314,7 @@ finish_member_template_decl (tree decl) > return DECL_TI_TEMPLATE (decl); > } > else > - return decl; > + return NULL_TREE; > } > else > error_at (DECL_SOURCE_LOCATION (decl), > diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ84.C b/gcc/testsuite/g++.dg/cpp1y/var-templ84.C > new file mode 100644 > index 00000000000..39c2a0dc0cc > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ84.C > @@ -0,0 +1,12 @@ > +// PR c++/71954 > +// { dg-do compile { target c++14 } } > + > +struct A { > + template static const int var = 0; > + template static const int var = 1; > + template static const int var = 2; > +}; > + > +static_assert(A::var == 0, ""); > +static_assert(A::var == 1, ""); > +static_assert(A::var == 2, ""); > diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ84a.C b/gcc/testsuite/g++.dg/cpp1y/var-templ84a.C > new file mode 100644 > index 00000000000..4aa3a2a7245 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ84a.C > @@ -0,0 +1,19 @@ > +// PR c++/71954 > +// A version of var-templ84.C where the partial specializations depend on > +// outer template parameters. > +// { dg-do compile { target c++14 } } > + > +template > +struct A { > + template static const int var = 0; > + template static const int var = 1; > + template static const int var = 2; > +}; > + > +static_assert(A::var == 0, ""); > +static_assert(A::var == 1, ""); > +static_assert(A::var == 2, ""); > + > +static_assert(A::var == 0, ""); > +static_assert(A::var == 0, ""); > +static_assert(A::var == 0, "");