summaryrefslogtreecommitdiff
path: root/gcc/cp/lambda.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/lambda.c')
-rw-r--r--gcc/cp/lambda.c127
1 files changed, 5 insertions, 122 deletions
diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index bb6c68a100a..4480c67dc5f 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -245,7 +245,8 @@ lambda_capture_field_type (tree expr, bool explicit_init_p,
{
type = non_reference (unlowered_expr_type (expr));
- if (!is_this && by_reference_p)
+ if (!is_this
+ && (by_reference_p || TREE_CODE (type) == FUNCTION_TYPE))
type = build_reference_type (type);
}
@@ -557,8 +558,7 @@ add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p,
{
gcc_assert (POINTER_TYPE_P (type));
type = TREE_TYPE (type);
- initializer = cp_build_indirect_ref (initializer, RO_NULL,
- tf_warning_or_error);
+ initializer = cp_build_fold_indirect_ref (initializer);
}
if (dependent_type_p (type))
@@ -862,8 +862,7 @@ maybe_resolve_dummy (tree object, bool add_capture_p)
if (tree lam = resolvable_dummy_lambda (object))
if (tree cap = lambda_expr_this_capture (lam, add_capture_p))
if (cap != error_mark_node)
- object = build_x_indirect_ref (EXPR_LOCATION (object), cap,
- RO_NULL, tf_warning_or_error);
+ object = build_fold_indirect_ref (cap);
return object;
}
@@ -987,121 +986,6 @@ generic_lambda_fn_p (tree callop)
&& PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (callop)));
}
-/* Returns true iff we need to consider default capture for an enclosing
- generic lambda. */
-
-bool
-need_generic_capture (void)
-{
- if (!processing_template_decl)
- return false;
-
- tree outer_closure = NULL_TREE;
- for (tree t = current_class_type; t;
- t = decl_type_context (TYPE_MAIN_DECL (t)))
- {
- tree lam = CLASSTYPE_LAMBDA_EXPR (t);
- if (!lam || LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_NONE)
- /* No default capture. */
- break;
- outer_closure = t;
- }
-
- if (!outer_closure)
- /* No lambda. */
- return false;
- else if (dependent_type_p (outer_closure))
- /* The enclosing context isn't instantiated. */
- return false;
- else
- return true;
-}
-
-/* A lambda-expression...is said to implicitly capture the entity...if the
- compound-statement...names the entity in a potentially-evaluated
- expression where the enclosing full-expression depends on a generic lambda
- parameter declared within the reaching scope of the lambda-expression. */
-
-static tree
-dependent_capture_r (tree *tp, int *walk_subtrees, void *data)
-{
- hash_set<tree> *pset = (hash_set<tree> *)data;
-
- if (TYPE_P (*tp))
- *walk_subtrees = 0;
-
- if (outer_automatic_var_p (*tp))
- {
- tree t = process_outer_var_ref (*tp, tf_warning_or_error, /*force*/true);
- if (t != *tp
- && TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE
- && TREE_CODE (TREE_TYPE (*tp)) != REFERENCE_TYPE)
- t = convert_from_reference (t);
- *tp = t;
- }
-
- if (pset->add (*tp))
- *walk_subtrees = 0;
-
- switch (TREE_CODE (*tp))
- {
- /* Don't walk into unevaluated context or another lambda. */
- case SIZEOF_EXPR:
- case ALIGNOF_EXPR:
- case TYPEID_EXPR:
- case NOEXCEPT_EXPR:
- case LAMBDA_EXPR:
- *walk_subtrees = 0;
- break;
-
- /* Don't walk into statements whose subexpressions we already
- handled. */
- case TRY_BLOCK:
- case EH_SPEC_BLOCK:
- case HANDLER:
- case IF_STMT:
- case FOR_STMT:
- case RANGE_FOR_STMT:
- case WHILE_STMT:
- case DO_STMT:
- case SWITCH_STMT:
- case STATEMENT_LIST:
- case RETURN_EXPR:
- *walk_subtrees = 0;
- break;
-
- case DECL_EXPR:
- {
- tree decl = DECL_EXPR_DECL (*tp);
- if (VAR_P (decl))
- {
- /* walk_tree_1 won't step in here. */
- cp_walk_tree (&DECL_INITIAL (decl),
- dependent_capture_r, &pset, NULL);
- *walk_subtrees = 0;
- }
- }
- break;
-
- default:
- break;
- }
-
- return NULL_TREE;
-}
-
-tree
-do_dependent_capture (tree expr, bool force)
-{
- if (!need_generic_capture ()
- || (!force && !instantiation_dependent_expression_p (expr)))
- return expr;
-
- hash_set<tree> pset;
- cp_walk_tree (&expr, dependent_capture_r, &pset, NULL);
- return expr;
-}
-
/* If the closure TYPE has a static op(), also add a conversion to function
pointer. */
@@ -1154,8 +1038,7 @@ maybe_add_lambda_conv_op (tree type)
return expression for a deduced return call op to allow for simple
implementation of the conversion operator. */
- tree instance = cp_build_indirect_ref (thisarg, RO_NULL,
- tf_warning_or_error);
+ tree instance = cp_build_fold_indirect_ref (thisarg);
tree objfn = build_min (COMPONENT_REF, NULL_TREE,
instance, DECL_NAME (callop), NULL_TREE);
int nargs = list_length (DECL_ARGUMENTS (callop)) - 1;