current_class_type = saved_class_type;
return member;
-
}
/* Return the capture pertaining to a use of 'this' in LAMBDA, in the form of an
{
tree containing_function = TYPE_CONTEXT (TREE_TYPE (lambda));
tree lambda_stack = tree_cons (NULL_TREE, lambda, NULL_TREE);
+ tree init = NULL_TREE;
/* If we are in a lambda function, we can move out until we hit:
1. a non-lambda function,
tree lambda
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (containing_function));
- if (LAMBDA_EXPR_THIS_CAPTURE (lambda)
- || LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda) == CPLD_NONE)
- break;
+ if (LAMBDA_EXPR_THIS_CAPTURE (lambda))
+ {
+ /* An outer lambda has already captured 'this'. */
+ tree cap = LAMBDA_EXPR_THIS_CAPTURE (lambda);
+ tree lthis
+ = cp_build_indirect_ref (DECL_ARGUMENTS (containing_function),
+ "", tf_warning_or_error);
+ init = finish_non_static_data_member (cap, lthis, NULL_TREE);
+ break;
+ }
+
+ if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda) == CPLD_NONE)
+ /* An outer lambda won't let us capture 'this'. */
+ break;
lambda_stack = tree_cons (NULL_TREE,
lambda,
containing_function = decl_function_context (containing_function);
}
- if (DECL_NONSTATIC_MEMBER_FUNCTION_P (containing_function))
- {
- this_capture = add_default_capture (lambda_stack,
- /*id=*/get_identifier ("__this"),
- /* First parameter is 'this'. */
- /*initializer=*/DECL_ARGUMENTS
- (containing_function));
- }
+ if (!init && DECL_NONSTATIC_MEMBER_FUNCTION_P (containing_function)
+ && !LAMBDA_FUNCTION_P (containing_function))
+ /* First parameter is 'this'. */
+ init = DECL_ARGUMENTS (containing_function);
+ if (init)
+ this_capture = add_default_capture (lambda_stack,
+ /*id=*/get_identifier ("__this"),
+ init);
}
if (!this_capture)