aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/lambda.cc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-04-06 22:20:49 -0400
committerJason Merrill <jason@redhat.com>2022-04-06 23:25:56 -0400
commit8e4339f5023286d25c7dfa40b4c88e63b780cfd7 (patch)
treec8eb6556a57a41b2430b41f4b8c9e8d0478b4ec9 /gcc/cp/lambda.cc
parent2dda1094a7c195398c3f2b31519f427ac7d97956 (diff)
downloadgcc-8e4339f5023286d25c7dfa40b4c88e63b780cfd7.zip
gcc-8e4339f5023286d25c7dfa40b4c88e63b780cfd7.tar.gz
gcc-8e4339f5023286d25c7dfa40b4c88e63b780cfd7.tar.bz2
c++: nested generic lambda in DMI [PR101717]
We were already checking COMPLETE_TYPE_P to recognize instantiation of a generic lambda, but didn't consider that we might be nested in a non-generic lambda. PR c++/101717 gcc/cp/ChangeLog: * lambda.cc (lambda_expr_this_capture): Check all enclosing lambdas for completeness. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/lambda-generic-this4.C: New test.
Diffstat (limited to 'gcc/cp/lambda.cc')
-rw-r--r--gcc/cp/lambda.cc8
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc
index 4cc3a47..f22798d 100644
--- a/gcc/cp/lambda.cc
+++ b/gcc/cp/lambda.cc
@@ -741,6 +741,7 @@ lambda_expr_this_capture (tree lambda, int add_capture_p)
{
tree lambda_stack = NULL_TREE;
tree init = NULL_TREE;
+ bool saw_complete = false;
/* If we are in a lambda function, we can move out until we hit:
1. a non-lambda function or NSDMI,
@@ -759,6 +760,11 @@ lambda_expr_this_capture (tree lambda, int add_capture_p)
lambda_stack);
tree closure = LAMBDA_EXPR_CLOSURE (tlambda);
+ if (COMPLETE_TYPE_P (closure))
+ /* We're instantiating a generic lambda op(), the containing
+ scope may be gone. */
+ saw_complete = true;
+
tree containing_function
= decl_function_context (TYPE_NAME (closure));
@@ -768,7 +774,7 @@ lambda_expr_this_capture (tree lambda, int add_capture_p)
/* Lambda in an NSDMI. We don't have a function to look up
'this' in, but we can find (or rebuild) the fake one from
inject_this_parameter. */
- if (!containing_function && !COMPLETE_TYPE_P (closure))
+ if (!containing_function && !saw_complete)
/* If we're parsing a lambda in a non-local class,
we can find the fake 'this' in scope_chain. */
init = scope_chain->x_current_class_ptr;