From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id D5BA03858D28; Wed, 15 Dec 2021 19:55:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D5BA03858D28 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9389] c++: template-id ADL and partial instantiation [PR99911] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: a94867f67e0b48ba53691f1d5f43f5c7d60adecb X-Git-Newrev: 5a2c4c1e171d2681a506f6de2235a32293e69b3f Message-Id: <20211215195525.D5BA03858D28@sourceware.org> Date: Wed, 15 Dec 2021 19:55:25 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Dec 2021 19:55:25 -0000 https://gcc.gnu.org/g:5a2c4c1e171d2681a506f6de2235a32293e69b3f commit r11-9389-g5a2c4c1e171d2681a506f6de2235a32293e69b3f Author: Patrick Palka Date: Thu Nov 18 10:05:13 2021 -0500 c++: template-id ADL and partial instantiation [PR99911] Here when partially instantiating the call get(T{}) with T=N::A (for which earlier unqualified name lookup for 'get' found nothing) the arguments after substitution are no longer dependent but the callee still is, so perform_koenig_lookup postpones ADL. But then we go on to diagnose the unresolved template name anyway, as if ADL was already performed and failed. This patch fixes this by avoiding the error path in question when the template arguments of an unresolved template-id are still dependent, mirroring the dependence check in perform_koenig_lookup. PR c++/99911 gcc/cp/ChangeLog: * pt.c (tsubst_copy_and_build) : Don't diagnose name lookup failure if the arguments to an unresolved template name are still dependent. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/fn-template24.C: New test. (cherry picked from commit 90de06a7b3ce6ae8381136e58a2dde91fbbb6eff) Diff: --- gcc/cp/pt.c | 4 +++- gcc/testsuite/g++.dg/cpp2a/fn-template24.C | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index d2b35da89a1..c1a60cae697 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -20312,7 +20312,9 @@ tsubst_copy_and_build (tree t, if (function != NULL_TREE && (identifier_p (function) || (TREE_CODE (function) == TEMPLATE_ID_EXPR - && identifier_p (TREE_OPERAND (function, 0)))) + && identifier_p (TREE_OPERAND (function, 0)) + && !any_dependent_template_arguments_p (TREE_OPERAND + (function, 1)))) && !any_type_dependent_arguments_p (call_args)) { if (TREE_CODE (function) == TEMPLATE_ID_EXPR) diff --git a/gcc/testsuite/g++.dg/cpp2a/fn-template24.C b/gcc/testsuite/g++.dg/cpp2a/fn-template24.C new file mode 100644 index 00000000000..b444ac6a273 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/fn-template24.C @@ -0,0 +1,16 @@ +// PR c++/99911 +// { dg-do compile { target c++20 } } + +namespace N { + struct A { }; + template void get(A); +}; + +template +auto f() { + return [](U) { get(T{}); }; +} + +int main() { + f()(0); +}