c++: template-id ADL and partial instantiation [PR99911]

Here when partially instantiating the call get<U>(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) <case CALL_EXPR>: 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.
This commit is contained in:
Patrick Palka 2021-11-18 10:05:13 -05:00
parent 6fa8e0896c
commit 90de06a7b3
2 changed files with 19 additions and 1 deletions

View File

@ -20434,7 +20434,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)

View File

@ -0,0 +1,16 @@
// PR c++/99911
// { dg-do compile { target c++20 } }
namespace N {
struct A { };
template<class T> void get(A);
};
template<class T>
auto f() {
return []<class U>(U) { get<U>(T{}); };
}
int main() {
f<N::A>()(0);
}