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 [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id CDA913858023 for ; Fri, 5 Mar 2021 21:21:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CDA913858023 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-336-yFA93g9MN2KuiPZCcaNKUQ-1; Fri, 05 Mar 2021 16:21:30 -0500 X-MC-Unique: yFA93g9MN2KuiPZCcaNKUQ-1 Received: by mail-qt1-f200.google.com with SMTP id v19so2792322qtw.19 for ; Fri, 05 Mar 2021 13:21:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=UOj1M95NA8WILXDOjQpmzKkZv1wslH886drz5cX51Wc=; b=L06sIPPFnLweuCC5sn1dlzcUWXf0PdZ9YuBhEwvL0cJBrdYZGt1JUZ8QbJ9E8qskQS xjWzbqWy/Y7AKKz0Hg0g4Mbc75qRWFDwrAOA6Ppr4BajYsBBuBhvuNCBUKbyJY/JWeIZ noB4r0TFGG2fBO18v6tsp+Re3NnWVNo+v/gZKDa0f3KE3D7mt54yvpVp6RDmfZYKglCA 3EsMxZyWTE7X80Qn9mdN2NO+xoJoHWcqUWG2xLyPwyWIq3xBA5a7v01tJFQpchBsxIr1 /0wE04AHL/cXUx7dvWywmD6Ia9d+T7FJ3BqRnbasY2y5pn4DrDkeDxu0sLCvnD8nPKVH zoYA== X-Gm-Message-State: AOAM5305gBu2bnFzHtNan+uvqX+pNyqdn1OSfL1WT2Eeo9hFlXratPC9 0zWUzCIre5KeXwQcyB6newpI8f8P5tFNpYZw4yhhVZ88MyIwaY9zQ3VXokhjqZorLjaQhcFADvR M23EVYRiYj5mPB01mYA== X-Received: by 2002:a37:a9cf:: with SMTP id s198mr10650406qke.143.1614979290161; Fri, 05 Mar 2021 13:21:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5Wk5SV1cOQNdb39+CkUF1ULy1351YZM3NBswPL7ezrfcbtBzime+Z/DfgnbV/9yRYCTLOmw== X-Received: by 2002:a37:a9cf:: with SMTP id s198mr10650392qke.143.1614979289916; Fri, 05 Mar 2021 13:21:29 -0800 (PST) Received: from [192.168.1.148] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id d84sm2648023qke.53.2021.03.05.13.21.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Mar 2021 13:21:29 -0800 (PST) Subject: Re: [PATCH] c++: Fix tsubsting member variable template-id [PR96330] To: Patrick Palka , gcc-patches@gcc.gnu.org Cc: Jakub Jelinek References: <20210305180446.3640500-1-ppalka@redhat.com> From: Jason Merrill Message-ID: <406b716d-b94c-b90c-9e52-34a13fb2988b@redhat.com> Date: Fri, 5 Mar 2021 16:21:28 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <20210305180446.3640500-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-15.7 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Mar 2021 21:21:34 -0000 On 3/5/21 1:04 PM, Patrick Palka wrote: > This makes tsubst_copy appropriately handle a variable template-id, which > in turn fixes tsubsting a COMPONENT_REF whose member operand is known at > parse time to be a variable template-id, as in the initialization of 'x' > in the first testcase. Previously, we rejected this testcase with the > error "foo_t::bar is not a function template", issued from > lookup_template_fuction. > > We were already properly handling the analagous case where the object > operand of the COMPONENT_REF is dependent (and so the member operand is > a dependent template name), but there doesn't seems to be existing test > coverage for this, hence the second testcase below. > > Bootstrapped and regtested on x86_64-pc-linux-gnu. Does this look OK > for trunk or perhaps GCC 12? OK for trunk. > gcc/cp/ChangeLog: > > PR c++/96330 > * pt.c (tsubst_copy) : Rename local > variable 'fn' to 'tmpl'. Handle a variable template-id by > calling lookup_template_variable. > > gcc/testsuite/ChangeLog: > > PR c++/96330 > * g++.dg/cpp1y/var-templ68.C: New test. > * g++.dg/cpp1y/var-templ68a.C: New test. > > Co-authored-by: Jakub Jelinek > --- > gcc/cp/pt.c | 9 ++++++--- > gcc/testsuite/g++.dg/cpp1y/var-templ68.C | 15 +++++++++++++++ > gcc/testsuite/g++.dg/cpp1y/var-templ68a.C | 16 ++++++++++++++++ > 3 files changed, 37 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ68.C > create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ68a.C > > diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c > index ec869451cd2..c956815ce85 100644 > --- a/gcc/cp/pt.c > +++ b/gcc/cp/pt.c > @@ -17108,14 +17108,17 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) > case TEMPLATE_ID_EXPR: > { > /* Substituted template arguments */ > - tree fn = TREE_OPERAND (t, 0); > + tree tmpl = TREE_OPERAND (t, 0); > tree targs = TREE_OPERAND (t, 1); > > - fn = tsubst_copy (fn, args, complain, in_decl); > + tmpl = tsubst_copy (tmpl, args, complain, in_decl); > if (targs) > targs = tsubst_template_args (targs, args, complain, in_decl); > > - return lookup_template_function (fn, targs); > + if (variable_template_p (tmpl)) > + return lookup_template_variable (tmpl, targs); > + else > + return lookup_template_function (tmpl, targs); > } > > case TREE_LIST: > diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ68.C b/gcc/testsuite/g++.dg/cpp1y/var-templ68.C > new file mode 100644 > index 00000000000..4c560d4bd35 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ68.C > @@ -0,0 +1,15 @@ > +// PR c++/96330 > +// { dg-do compile { target c++14 } } > + > +struct foo_t { > + template static constexpr bool bar = true; > +}; > +constexpr foo_t foo{}; > + > +template > +void f() { > + int x = foo.bar; > + int y = foo_t::bar; > +} > + > +template void f(); > diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ68a.C b/gcc/testsuite/g++.dg/cpp1y/var-templ68a.C > new file mode 100644 > index 00000000000..6091a03a004 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ68a.C > @@ -0,0 +1,16 @@ > +// PR c++/96330 > +// { dg-do compile { target c++14 } } > + > +template > +struct foo_t { > + template static constexpr bool bar = true; > +}; > +template constexpr foo_t foo{}; > + > +template > +void f() { > + int x = foo.template bar; > + int y = foo_t::template bar; > +} > + > +template void f(); >