From 0744a0c1155bca3b0fee47ad2ac40a2652968bd4 Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 13 Nov 2017 22:12:55 +0000 Subject: Defer folding of *&. * typeck.c (cp_build_fold_indirect_ref): New. (cp_build_indirect_ref_1): Split out from cp_build_indirect_ref. Add 'fold' parameter. * cp-tree.h: Declare cp_build_fold_indirect_ref. * call.c, class.c, cp-ubsan.c, decl.c, except.c, init.c, lambda.c, parser.c, rtti.c, tree.c, typeck.c, typeck2.c: Use it. * parser.c (do_range_for_auto_deduction): Use RO_UNARY_STAR. (cp_convert_range_for): Likewise. * typeck2.c (build_x_arrow): Use RO_ARROW. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254712 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/lambda.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'gcc/cp/lambda.c') diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index bb6c68a100a..7c8b6409409 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -557,8 +557,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 +861,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; } @@ -1154,8 +1152,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; -- cgit v1.2.1 From 297de7bc513f3f2eb82dde14ecc7f0661aa667db Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 13 Nov 2017 22:34:38 +0000 Subject: Capture adjustments for P0588R1. * semantics.c (process_outer_var_ref): Capture variables when they are named; complain about non-capture uses when odr-used. * expr.c (mark_use): Rvalue use looks through capture proxy. * constexpr.c (potential_constant_expression_1): Improve error about use of captured variable. * lambda.c (need_generic_capture, dependent_capture_r) (do_dependent_capture, processing_nonlambda_template): Remove. * call.c (build_this): Remove uses of the above. * decl.c (cp_finish_decl): Likewise. * semantics.c (maybe_cleanup_point_expr) (maybe_cleanup_point_expr_void, finish_goto_stmt) (maybe_convert_cond): Likewise. * typeck.c (check_return_expr): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254713 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/lambda.c | 115 -------------------------------------------------------- 1 file changed, 115 deletions(-) (limited to 'gcc/cp/lambda.c') diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 7c8b6409409..2cbad878ff6 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -985,121 +985,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 *pset = (hash_set *)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 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. */ -- cgit v1.2.1 From d46b9539e69f8b183765c93a432a2e027adb7036 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 15 Nov 2017 13:18:09 +0000 Subject: [PR c++/81574] lambda capture of function reference https://gcc.gnu.org/ml/gcc-patches/2017-11/msg01200.html PR c++/81574 * lambda.c (lambda_capture_field_type): Function references are always catured by reference. PR c++/81574 * g++.dg/cpp1y/pr81574.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254768 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/lambda.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gcc/cp/lambda.c') diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 2cbad878ff6..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); } -- cgit v1.2.1