aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/lambda.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2017-08-29 16:37:15 -0400
committerJason Merrill <jason@gcc.gnu.org>2017-08-29 16:37:15 -0400
commitf44a8dd56f5bfbd0596c39693e268ef880c06221 (patch)
treeb1c3f161803fc2b6d6b610a8db75bddd8b2369d1 /gcc/cp/lambda.c
parent72932ccf0ac4837b020d29b386d75fbceeb88735 (diff)
downloadgcc-f44a8dd56f5bfbd0596c39693e268ef880c06221.zip
gcc-f44a8dd56f5bfbd0596c39693e268ef880c06221.tar.gz
gcc-f44a8dd56f5bfbd0596c39693e268ef880c06221.tar.bz2
Reimplement handling of lambdas in templates.
* cp-tree.h (LAMBDA_FUNCTION_P): Check DECL_DECLARES_FUNCTION_P. * decl.c (start_preparsed_function): Call start_lambda_scope. (finish_function): Call finish_lambda_scope. * init.c (get_nsdmi): Call start/finish_lambda_scope. * lambda.c (start_lambda_scope): Only ignore VAR_DECL in a function. * parser.c (cp_parser_function_definition_after_declarator): Don't call start/finish_lambda_scope. * pt.c (retrieve_specialization): Ignore lambda functions in templates. (find_parameter_packs_r): Ignore capture proxies. Look into lambdas. (check_for_bare_parameter_packs): Allow bare packs in lambdas. (tsubst_default_argument): Call start/finish_lambda_scope. (tsubst_function_decl): Handle lambda functions differently. (tsubst_template_decl): Likewise. (tsubst_expr) [DECL_EXPR]: Skip closure declarations and capture proxies. (tsubst_lambda_expr): Create a new closure rather than instantiate the one from the template. (tsubst_copy_and_build): Don't register a specialization of a pack. (regenerate_decl_from_template): Call start/finish_lambda_scope. (instantiate_decl): Remove special lambda function handling. * semantics.c (process_outer_var_ref): Remove special generic lambda handling. Don't implicitly capture in a lambda in a template. Look for an existing proxy. * class.c (current_nonlambda_class_type): Use decl_type_context. From-SVN: r251433
Diffstat (limited to 'gcc/cp/lambda.c')
-rw-r--r--gcc/cp/lambda.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index 55d3415..4747a72 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -1253,4 +1253,87 @@ is_lambda_ignored_entity (tree val)
return false;
}
+/* Lambdas that appear in variable initializer or default argument scope
+ get that in their mangling, so we need to record it. We might as well
+ use the count for function and namespace scopes as well. */
+static GTY(()) tree lambda_scope;
+static GTY(()) int lambda_count;
+struct GTY(()) tree_int
+{
+ tree t;
+ int i;
+};
+static GTY(()) vec<tree_int, va_gc> *lambda_scope_stack;
+
+void
+start_lambda_scope (tree decl)
+{
+ tree_int ti;
+ gcc_assert (decl);
+ /* Once we're inside a function, we ignore variable scope and just push
+ the function again so that popping works properly. */
+ if (current_function_decl && TREE_CODE (decl) == VAR_DECL)
+ decl = current_function_decl;
+ ti.t = lambda_scope;
+ ti.i = lambda_count;
+ vec_safe_push (lambda_scope_stack, ti);
+ if (lambda_scope != decl)
+ {
+ /* Don't reset the count if we're still in the same function. */
+ lambda_scope = decl;
+ lambda_count = 0;
+ }
+}
+
+void
+record_lambda_scope (tree lambda)
+{
+ LAMBDA_EXPR_EXTRA_SCOPE (lambda) = lambda_scope;
+ LAMBDA_EXPR_DISCRIMINATOR (lambda) = lambda_count++;
+}
+
+void
+finish_lambda_scope (void)
+{
+ tree_int *p = &lambda_scope_stack->last ();
+ if (lambda_scope != p->t)
+ {
+ lambda_scope = p->t;
+ lambda_count = p->i;
+ }
+ lambda_scope_stack->pop ();
+}
+
+tree
+start_lambda_function (tree fco, tree lambda_expr)
+{
+ /* Let the front end know that we are going to be defining this
+ function. */
+ start_preparsed_function (fco,
+ NULL_TREE,
+ SF_PRE_PARSED | SF_INCLASS_INLINE);
+
+ tree body = begin_function_body ();
+
+ /* Push the proxies for any explicit captures. */
+ for (tree cap = LAMBDA_EXPR_CAPTURE_LIST (lambda_expr); cap;
+ cap = TREE_CHAIN (cap))
+ build_capture_proxy (TREE_PURPOSE (cap));
+
+ return body;
+}
+
+void
+finish_lambda_function (tree body)
+{
+ finish_function_body (body);
+
+ /* Finish the function and generate code for it if necessary. */
+ tree fn = finish_function (/*inline*/2);
+
+ /* Only expand if the call op is not a template. */
+ if (!DECL_TEMPLATE_INFO (fn))
+ expand_or_defer_fn (fn);
+}
+
#include "gt-cp-lambda.h"