From 9925f216d0f85e8ee20900162b5238333f8e567e Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 29 Aug 2017 16:17:02 -0400 Subject: [PATCH] Remove unnecessary LAMBDA_EXPR fields. * cp-tree.h (LAMBDA_EXPR_CLOSURE): Use TREE_TYPE. (LAMBDA_EXPR_RETURN_TYPE): Remove. (struct tree_lambda_expr): Remove closure and return_type fields. * lambda.c (build_lambda_expr): Don't set LAMBDA_EXPR_RETURN_TYPE. * pt.c (tsubst_copy_and_build): Likewise. * parser.c (cp_parser_lambda_declarator_opt): Track return type. (cp_parser_lambda_body): Adjust unspecified return type check. * ptree.c (cxx_print_lambda_node): Don't print closure or return type. From-SVN: r251430 --- gcc/cp/ChangeLog | 16 +++++++++++----- gcc/cp/cp-tree.def | 3 +-- gcc/cp/cp-tree.h | 14 +++----------- gcc/cp/lambda.c | 1 - gcc/cp/parser.c | 12 ++++++------ gcc/cp/pt.c | 3 --- gcc/cp/ptree.c | 2 -- gcc/cp/semantics.c | 6 ------ 8 files changed, 21 insertions(+), 36 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4d6df428efd..ef7f4292d4d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,4 +1,14 @@ -2017-08-28 Jason Merrill +2017-08-29 Jason Merrill + + * cp-tree.h (LAMBDA_EXPR_CLOSURE): Use TREE_TYPE. + (LAMBDA_EXPR_RETURN_TYPE): Remove. + (struct tree_lambda_expr): Remove closure and return_type fields. + * lambda.c (build_lambda_expr): Don't set LAMBDA_EXPR_RETURN_TYPE. + * pt.c (tsubst_copy_and_build): Likewise. + * parser.c (cp_parser_lambda_declarator_opt): Track return type. + (cp_parser_lambda_body): Adjust unspecified return type check. + * ptree.c (cxx_print_lambda_node): Don't print closure or + return type. PR c++/80935 - wrong C++17 error with lambda * decl.c (check_for_uninitialized_const_var): Check @@ -7,16 +17,12 @@ is_instantiation_of_constexpr. (potential_constant_expression_1): Check var_in_maybe_constexpr_fn. -2017-08-23 Jason Merrill - * lambda.c (build_lambda_object): Check for error_mark_node. * pt.c (make_pack_expansion): Set PACK_EXPANSION_LOCAL_P on the type pack as well. (tsubst_decl) [FUNCTION_DECL]: Set DECL_CONTEXT on the parameters. (tsubst) [TEMPLATE_PARM_INDEX]: Check for error_mark_node. -2017-08-29 Jason Merrill - PR c++/80767 - unnecessary instantiation of generic lambda * call.c (convert_like_real): Call build_user_type_conversion_1 if cand is null. diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def index a46f9c33cb4..890723f20ef 100644 --- a/gcc/cp/cp-tree.def +++ b/gcc/cp/cp-tree.def @@ -468,8 +468,7 @@ DEFTREECODE (TRAIT_EXPR, "trait_expr", tcc_exceptional, 0) LAMBDA_EXPR_THIS_CAPTURE goes straight to the capture of `this', if it exists. LAMBDA_EXPR_PENDING_PROXIES is a vector of capture proxies which need to be pushed once scope returns to the lambda. - LAMBDA_EXPR_MUTABLE_P signals whether this lambda was declared mutable. - LAMBDA_EXPR_RETURN_TYPE holds the return type, if it was specified. */ + LAMBDA_EXPR_MUTABLE_P signals whether this lambda was declared mutable. */ DEFTREECODE (LAMBDA_EXPR, "lambda_expr", tcc_exceptional, 0) /* The declared type of an expression. This is a C++0x extension. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index a58e7bd0cc0..ad97be4c1ce 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1253,11 +1253,6 @@ enum cp_lambda_default_capture_mode_type { #define LAMBDA_EXPR_MUTABLE_P(NODE) \ TREE_LANG_FLAG_1 (LAMBDA_EXPR_CHECK (NODE)) -/* The return type in the expression. - * NULL_TREE indicates that none was specified. */ -#define LAMBDA_EXPR_RETURN_TYPE(NODE) \ - (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->return_type) - /* The source location of the lambda. */ #define LAMBDA_EXPR_LOCATION(NODE) \ (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->locus) @@ -1276,20 +1271,17 @@ enum cp_lambda_default_capture_mode_type { #define LAMBDA_EXPR_PENDING_PROXIES(NODE) \ (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->pending_proxies) -/* The closure type of the lambda. Note that the TREE_TYPE of a - LAMBDA_EXPR is always NULL_TREE, because we need to instantiate the - LAMBDA_EXPR in order to instantiate the type. */ +/* The closure type of the lambda, which is also the type of the + LAMBDA_EXPR. */ #define LAMBDA_EXPR_CLOSURE(NODE) \ - (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->closure) + (TREE_TYPE (LAMBDA_EXPR_CHECK (NODE))) struct GTY (()) tree_lambda_expr { struct tree_typed typed; tree capture_list; tree this_capture; - tree return_type; tree extra_scope; - tree closure; vec *pending_proxies; location_t locus; enum cp_lambda_default_capture_mode_type default_capture_mode; diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 337b9ee3c62..55d3415676c 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -42,7 +42,6 @@ build_lambda_expr (void) LAMBDA_EXPR_CAPTURE_LIST (lambda) = NULL_TREE; LAMBDA_EXPR_THIS_CAPTURE (lambda) = NULL_TREE; LAMBDA_EXPR_PENDING_PROXIES (lambda) = NULL; - LAMBDA_EXPR_RETURN_TYPE (lambda) = NULL_TREE; LAMBDA_EXPR_MUTABLE_P (lambda) = false; return lambda; } diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index d66f1463efa..9f62b4310e7 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -10416,6 +10416,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) tree exception_spec = NULL_TREE; tree template_param_list = NULL_TREE; tree tx_qual = NULL_TREE; + tree return_type = NULL_TREE; cp_decl_specifier_seq lambda_specs; clear_decl_specs (&lambda_specs); @@ -10490,8 +10491,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) if (cp_lexer_next_token_is (parser->lexer, CPP_DEREF)) { cp_lexer_consume_token (parser->lexer); - LAMBDA_EXPR_RETURN_TYPE (lambda_expr) - = cp_parser_trailing_type_id (parser); + return_type = cp_parser_trailing_type_id (parser); } /* The function parameters must be in scope all the way until after the @@ -10514,8 +10514,8 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) void *p; clear_decl_specs (&return_type_specs); - if (LAMBDA_EXPR_RETURN_TYPE (lambda_expr)) - return_type_specs.type = LAMBDA_EXPR_RETURN_TYPE (lambda_expr); + if (return_type) + return_type_specs.type = return_type; else /* Maybe we will deduce the return type later. */ return_type_specs.type = make_auto (); @@ -10555,7 +10555,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) DECL_ARTIFICIAL (fco) = 1; /* Give the object parameter a different name. */ DECL_NAME (DECL_ARGUMENTS (fco)) = get_identifier ("__closure"); - if (LAMBDA_EXPR_RETURN_TYPE (lambda_expr)) + if (return_type) TYPE_HAS_LATE_RETURN_TYPE (TREE_TYPE (fco)) = 1; } if (template_param_list) @@ -10645,7 +10645,7 @@ cp_parser_lambda_body (cp_parser* parser, tree lambda_expr) nor a deducible form, errors should be reported for return statements in the body. Since we used void as the placeholder return type, parsing the body as usual will give such desired behavior. */ - if (!LAMBDA_EXPR_RETURN_TYPE (lambda_expr) + if (is_auto (TREE_TYPE (TREE_TYPE (fco))) && cp_lexer_peek_nth_token (parser->lexer, 1)->keyword == RID_RETURN && cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SEMICOLON) { diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index aaae06d96c7..e064a11c05b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -17979,9 +17979,6 @@ tsubst_copy_and_build (tree t, declaration of the op() for later calls to lambda_function. */ complete_type (type); - if (tree fn = lambda_function (type)) - LAMBDA_EXPR_RETURN_TYPE (r) = TREE_TYPE (TREE_TYPE (fn)); - LAMBDA_EXPR_THIS_CAPTURE (r) = NULL_TREE; insert_pending_capture_proxies (); diff --git a/gcc/cp/ptree.c b/gcc/cp/ptree.c index 24efe27e5e2..50c717e286e 100644 --- a/gcc/cp/ptree.c +++ b/gcc/cp/ptree.c @@ -204,8 +204,6 @@ cxx_print_lambda_node (FILE *file, tree node, int indent) fprintf (file, "] "); print_node (file, "capture_list", LAMBDA_EXPR_CAPTURE_LIST (node), indent + 4); print_node (file, "this_capture", LAMBDA_EXPR_THIS_CAPTURE (node), indent + 4); - print_node (file, "return_type", LAMBDA_EXPR_RETURN_TYPE (node), indent + 4); - print_node (file, "closure", LAMBDA_EXPR_CLOSURE (node), indent + 4); } void diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 86ce9ce9461..fe118cd97af 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -9363,12 +9363,6 @@ apply_deduced_return_type (tree fco, tree return_type) if (return_type == error_mark_node) return; - if (LAMBDA_FUNCTION_P (fco)) - { - tree lambda = CLASSTYPE_LAMBDA_EXPR (current_class_type); - LAMBDA_EXPR_RETURN_TYPE (lambda) = return_type; - } - if (DECL_CONV_FN_P (fco)) DECL_NAME (fco) = make_conv_op_name (return_type); -- 2.30.2