diff options
author | Jason Merrill <jason@redhat.com> | 2018-06-01 23:14:44 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2018-06-01 23:14:44 -0400 |
commit | 4cda703ebcfebec0d79f43c98cfca11e911d5b64 (patch) | |
tree | 46665a006f15c20cb88feaca29b8d593d401eca6 /gcc/cp/lambda.c | |
parent | 946d79a61ca8c7dd2872c43fffaec432fe7b46e6 (diff) | |
download | gcc-4cda703ebcfebec0d79f43c98cfca11e911d5b64.zip gcc-4cda703ebcfebec0d79f43c98cfca11e911d5b64.tar.gz gcc-4cda703ebcfebec0d79f43c98cfca11e911d5b64.tar.bz2 |
PR c++/85764 - bogus 'this' not captured error.
* lambda.c (resolvable_dummy_lambda): Use nonlambda_method_basetype.
(nonlambda_method_basetype): Handle NSDMI.
From-SVN: r261101
Diffstat (limited to 'gcc/cp/lambda.c')
-rw-r--r-- | gcc/cp/lambda.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 9c1b49b..231490f 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -884,7 +884,7 @@ resolvable_dummy_lambda (tree object) && current_class_type && LAMBDA_TYPE_P (current_class_type) && lambda_function (current_class_type) - && DERIVED_FROM_P (type, current_nonlambda_class_type ())) + && DERIVED_FROM_P (type, nonlambda_method_basetype())) return CLASSTYPE_LAMBDA_EXPR (current_class_type); return NULL_TREE; @@ -949,30 +949,37 @@ current_nonlambda_function (void) return fn; } -/* Returns the method basetype of the innermost non-lambda function, or - NULL_TREE if none. */ +/* Returns the method basetype of the innermost non-lambda function, including + a hypothetical constructor if inside an NSDMI, or NULL_TREE if none. */ tree nonlambda_method_basetype (void) { - tree fn, type; if (!current_class_ref) return NULL_TREE; - type = current_class_type; + tree type = current_class_type; if (!type || !LAMBDA_TYPE_P (type)) return type; - /* Find the nearest enclosing non-lambda function. */ - fn = TYPE_NAME (type); - do - fn = decl_function_context (fn); - while (fn && LAMBDA_FUNCTION_P (fn)); - - if (!fn || !DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)) - return NULL_TREE; - - return TYPE_METHOD_BASETYPE (TREE_TYPE (fn)); + while (true) + { + tree lam = CLASSTYPE_LAMBDA_EXPR (type); + tree ex = LAMBDA_EXPR_EXTRA_SCOPE (lam); + if (ex && TREE_CODE (ex) == FIELD_DECL) + /* Lambda in an NSDMI. */ + return DECL_CONTEXT (ex); + + tree fn = TYPE_CONTEXT (type); + if (!fn || TREE_CODE (fn) != FUNCTION_DECL + || !DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)) + /* No enclosing non-lambda method. */ + return NULL_TREE; + if (!LAMBDA_FUNCTION_P (fn)) + /* Found an enclosing non-lambda method. */ + return TYPE_METHOD_BASETYPE (TREE_TYPE (fn)); + type = DECL_CONTEXT (fn); + } } /* Like current_scope, but looking through lambdas. */ |