diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2e31663c277..ad51c07347b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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) 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); +}