c++: local fn and generic lambda [PR97219]
commit1824da60663b4532199ecd051d8ba6da8995821d
authorJason Merrill <jason@redhat.com>
Wed, 13 Apr 2022 20:42:25 +0000 (13 16:42 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 14 Apr 2022 00:24:36 +0000 (13 20:24 -0400)
tree52bc8b3bc1d5569d87d6895f6d7af0da58d8c59e
parentd4e00ccef6c706a4a4a6446bffaf4111f98d5771
c++: local fn and generic lambda [PR97219]

When instantiating the op() for a generic lambda, we can no longer do name
lookup inside function scopes enclosing the lambda, so we need to remember
the lookup result from processing the definition of the lambda.  So the code
in finish_call_expr to throw away the lookup result and instead look it up
again at instantiation time needs to be adjusted.  The approach I take is to
only discard the result if the local extern comes from dependent scope; once
the enclosing function template is instantiated and we're regenerating the
lambda, then we can remember the result of lookup.  We also need any default
arguments to be instantiated at that point.

PR c++/97219

gcc/cp/ChangeLog:

* name-lookup.cc (dependent_local_decl_p): New.
* cp-tree.h (dependent_local_decl_p): Declare.
* semantics.cc (finish_call_expr): Use it.
* pt.cc (tsubst_arg_types): Also substitute default args
for local externs.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/lambda-generic-local-fn1.C: New test.
gcc/cp/cp-tree.h
gcc/cp/name-lookup.cc
gcc/cp/pt.cc
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/cpp1y/lambda-generic-local-fn1.C [new file with mode: 0644]