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 807A43861836 for ; Fri, 5 Mar 2021 18:04:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 807A43861836 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-188-Qjc2C7W2MKKWkTmvpFJQHw-1; Fri, 05 Mar 2021 13:04:53 -0500 X-MC-Unique: Qjc2C7W2MKKWkTmvpFJQHw-1 Received: by mail-qv1-f70.google.com with SMTP id h12so2139582qvm.9 for ; Fri, 05 Mar 2021 10:04:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+w8D5Z+O62HNUWf5ngYgxBhi9N/NPcPJfc7QVOOJZkQ=; b=GGA+4tvhXvyAczLHE99aiRdw4CG8w51odJzAUmrlEr+B2upojwjlKs3tfVT4Mtl3H7 XD38OJanVJ6R10hWbDXeUBeeoXiYKxueIHMxrzeoliS6Jf+tVSIetIzmWeHkGpln6Rhy JhWM8YvpITq2/xmbfATwN0csAx823hL17LYN4a13NVod6ZSj7N0muLJMRoSyjjry4bT+ 6Hf09UdkhcwNDApwNIWox+NJ9FRXtzoMmtrHO+f15alabAEcNHQDWQBtSpxZnagqspkv 73SuJl5cTFTPtKd9hO22D8vBwYJA5tKHGFn0SkBumlbwLfruWN1uPBW+vm7zsn+WgzEM cvpg== X-Gm-Message-State: AOAM530UEKl9lrwT8LFB4rU5ReZOnqqXT+dkZnSSGizp8tqYh5xEh4nj 6bekPkYee8lbuEEsunOrCEjPrDA6qClR+Q5Dktli/oU03/yfWtk/Y4hsD1NIW+C/kv7Hrb1Nj4x eehOaKJlmxXVgQMd0RRK2xXJU9husglXDpL078LLViBHf9a+RfG18Hg3NZCKWij8ZF2k= X-Received: by 2002:a05:620a:22b5:: with SMTP id p21mr10406726qkh.196.1614967492077; Fri, 05 Mar 2021 10:04:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/IMoN5pQ0+DYQaqUWUrA3sbCawEVZfRTuktZLfxc0ICBKq3s8RlgrNRZL54L5fxYIVLocfw== X-Received: by 2002:a05:620a:22b5:: with SMTP id p21mr10406704qkh.196.1614967491760; Fri, 05 Mar 2021 10:04:51 -0800 (PST) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id e3sm2388001qtj.28.2021.03.05.10.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 10:04:51 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka , Jakub Jelinek Subject: [PATCH] c++: Fix tsubsting member variable template-id [PR96330] Date: Fri, 5 Mar 2021 13:04:46 -0500 Message-Id: <20210305180446.3640500-1-ppalka@redhat.com> X-Mailer: git-send-email 2.31.0.rc0.75.gec125d1bc1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-16.3 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_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 18:04:57 -0000 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? 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(); -- 2.31.0.rc0.75.gec125d1bc1