PR c++/41896
* semantics.c (outer_lambda_capture_p): Revert.
(add_capture): Only finish_member_declaration if
we're in the lambda class.
(register_capture_members): New.
* cp-tree.h: Declare it.
* parser.c (cp_parser_lambda_expression): Call it.
From-SVN: r156678
+2010-02-10 Jason Merrill <jason@redhat.com>
+
+ PR c++/41896
+ * semantics.c (outer_lambda_capture_p): Revert.
+ (add_capture): Only finish_member_declaration if
+ we're in the lambda class.
+ (register_capture_members): New.
+ * cp-tree.h: Declare it.
+ * parser.c (cp_parser_lambda_expression): Call it.
+
2010-02-10 Jason Merrill <jason@redhat.com>
PR c++/41896
2010-02-10 Jason Merrill <jason@redhat.com>
PR c++/41896
extern void apply_lambda_return_type (tree, tree);
extern tree add_capture (tree, tree, tree, bool, bool);
extern tree add_default_capture (tree, tree, tree);
extern void apply_lambda_return_type (tree, tree);
extern tree add_capture (tree, tree, tree, bool, bool);
extern tree add_default_capture (tree, tree, tree);
+extern void register_capture_members (tree);
extern tree lambda_expr_this_capture (tree);
extern void maybe_add_lambda_conv_op (tree);
extern tree lambda_expr_this_capture (tree);
extern void maybe_add_lambda_conv_op (tree);
it now. */
push_deferring_access_checks (dk_no_deferred);
it now. */
push_deferring_access_checks (dk_no_deferred);
+ cp_parser_lambda_introducer (parser, lambda_expr);
+
type = begin_lambda_type (lambda_expr);
record_lambda_scope (lambda_expr);
type = begin_lambda_type (lambda_expr);
record_lambda_scope (lambda_expr);
/* Do this again now that LAMBDA_EXPR_EXTRA_SCOPE is set. */
determine_visibility (TYPE_NAME (type));
/* Do this again now that LAMBDA_EXPR_EXTRA_SCOPE is set. */
determine_visibility (TYPE_NAME (type));
+ /* Now that we've started the type, add the capture fields for any
+ explicit captures. */
+ register_capture_members (LAMBDA_EXPR_CAPTURE_LIST (lambda_expr));
+
{
/* Inside the class, surrounding template-parameter-lists do not apply. */
unsigned int saved_num_template_parameter_lists
{
/* Inside the class, surrounding template-parameter-lists do not apply. */
unsigned int saved_num_template_parameter_lists
parser->num_template_parameter_lists = 0;
parser->num_template_parameter_lists = 0;
- cp_parser_lambda_introducer (parser, lambda_expr);
-
/* By virtue of defining a local class, a lambda expression has access to
the private variables of enclosing classes. */
/* By virtue of defining a local class, a lambda expression has access to
the private variables of enclosing classes. */
{
return (TREE_CODE (decl) == FIELD_DECL
&& LAMBDA_TYPE_P (DECL_CONTEXT (decl))
{
return (TREE_CODE (decl) == FIELD_DECL
&& LAMBDA_TYPE_P (DECL_CONTEXT (decl))
- /* Using current_class_type here causes problems with uses in a
- nested lambda-introducer; see 41896. */
- && DECL_CONTEXT (current_function_decl) != DECL_CONTEXT (decl));
+ && (!current_class_type
+ || !DERIVED_FROM_P (DECL_CONTEXT (decl), current_class_type)));
}
/* ID_EXPRESSION is a representation of parsed, but unprocessed,
}
/* ID_EXPRESSION is a representation of parsed, but unprocessed,
always visible. */
DECL_NORMAL_CAPTURE_P (member) = true;
always visible. */
DECL_NORMAL_CAPTURE_P (member) = true;
- /* Add it to the appropriate closure class. */
- finish_member_declaration (member);
+ /* Add it to the appropriate closure class if we've started it. */
+ if (current_class_type && current_class_type == TREE_TYPE (lambda))
+ finish_member_declaration (member);
LAMBDA_EXPR_CAPTURE_LIST (lambda)
= tree_cons (member, initializer, LAMBDA_EXPR_CAPTURE_LIST (lambda));
LAMBDA_EXPR_CAPTURE_LIST (lambda)
= tree_cons (member, initializer, LAMBDA_EXPR_CAPTURE_LIST (lambda));
+/* Register all the capture members on the list CAPTURES, which is the
+ LAMBDA_EXPR_CAPTURE_LIST for the lambda after the introducer. */
+
+void register_capture_members (tree captures)
+{
+ if (captures)
+ {
+ register_capture_members (TREE_CHAIN (captures));
+ finish_member_declaration (TREE_PURPOSE (captures));
+ }
+}
+
/* Given a FIELD_DECL decl belonging to a closure type, return a
COMPONENT_REF of it relative to the 'this' parameter of the op() for
that type. */
/* Given a FIELD_DECL decl belonging to a closure type, return a
COMPONENT_REF of it relative to the 'this' parameter of the op() for
that type. */