2017-05-08 Nathan Sidwell * name-lookup.h (pushdecl_with_scope): Replace with ... (pushdecl_outermost_localscope): ... this. * name-lookup.c (pushdecl_with_scope): Replace with ... (pushdecl_outermost_localscope): ... this. (pushdecl_namespace_level): Adjust. * decl.c (cp_make_fname_decl): Use pushdecl_outermost_localscope. * lambda.c (insert_capture_proxy): Likewise. Index: decl.c =================================================================== --- decl.c (revision 247751) +++ decl.c (working copy) @@ -4335,9 +4335,6 @@ cp_make_fname_decl (location_t loc, tree if (name) free (CONST_CAST (char *, name)); - /* As we're using pushdecl_with_scope, we must set the context. */ - DECL_CONTEXT (decl) = current_function_decl; - TREE_STATIC (decl) = 1; TREE_READONLY (decl) = 1; DECL_ARTIFICIAL (decl) = 1; @@ -4346,12 +4343,8 @@ cp_make_fname_decl (location_t loc, tree if (current_function_decl) { - cp_binding_level *b = current_binding_level; - if (b->kind == sk_function_parms) - return error_mark_node; - while (b->level_chain->kind != sk_function_parms) - b = b->level_chain; - pushdecl_with_scope (decl, b, /*is_friend=*/false); + DECL_CONTEXT (decl) = current_function_decl; + decl = pushdecl_outermost_localscope (decl); cp_finish_decl (decl, init, /*init_const_expr_p=*/false, NULL_TREE, LOOKUP_ONLYCONVERTING); } Index: lambda.c =================================================================== --- lambda.c (revision 247751) +++ lambda.c (working copy) @@ -295,24 +295,13 @@ is_normal_capture_proxy (tree decl) void insert_capture_proxy (tree var) { - cp_binding_level *b; - tree stmt_list; - /* Put the capture proxy in the extra body block so that it won't clash with a later local variable. */ - b = current_binding_level; - for (;;) - { - cp_binding_level *n = b->level_chain; - if (n->kind == sk_function_parms) - break; - b = n; - } - pushdecl_with_scope (var, b, false); + pushdecl_outermost_localscope (var); /* And put a DECL_EXPR in the STATEMENT_LIST for the same block. */ var = build_stmt (DECL_SOURCE_LOCATION (var), DECL_EXPR, var); - stmt_list = (*stmt_list_stack)[1]; + tree stmt_list = (*stmt_list_stack)[1]; gcc_assert (stmt_list); append_to_statement_list_force (var, &stmt_list); } Index: name-lookup.c =================================================================== --- name-lookup.c (revision 247751) +++ name-lookup.c (working copy) @@ -2870,14 +2870,23 @@ pushdecl_with_scope_1 (tree x, cp_bindin return x; } -/* Wrapper for pushdecl_with_scope_1. */ +/* Inject X into the local scope just before the function parms. */ tree -pushdecl_with_scope (tree x, cp_binding_level *level, bool is_friend) +pushdecl_outermost_localscope (tree x) { - tree ret; bool subtime = timevar_cond_start (TV_NAME_LOOKUP); - ret = pushdecl_with_scope_1 (x, level, is_friend); + cp_binding_level *b = NULL, *n = current_binding_level; + + if (n->kind == sk_function_parms) + return error_mark_node; + do + { + b = n; + n = b->level_chain; + } + while (n->kind != sk_function_parms); + tree ret = pushdecl_with_scope_1 (x, b, false); timevar_cond_stop (TV_NAME_LOOKUP, subtime); return ret; } @@ -4350,7 +4359,8 @@ pushdecl_namespace_level (tree x, bool i tree t; bool subtime = timevar_cond_start (TV_NAME_LOOKUP); - t = pushdecl_with_scope (x, NAMESPACE_LEVEL (current_namespace), is_friend); + t = pushdecl_with_scope_1 + (x, NAMESPACE_LEVEL (current_namespace), is_friend); /* Now, the type_shadowed stack may screw us. Munge it so it does what we want. */ Index: name-lookup.h =================================================================== --- name-lookup.h (revision 247751) +++ name-lookup.h (working copy) @@ -300,6 +300,7 @@ extern tree push_inner_scope (tree); extern void pop_inner_scope (tree, tree); extern void push_binding_level (cp_binding_level *); +extern tree pushdecl_outermost_localscope (tree); extern bool push_namespace (tree); extern void pop_namespace (void); extern void push_nested_namespace (tree); @@ -307,7 +308,6 @@ extern void pop_nested_namespace (tree); extern bool handle_namespace_attrs (tree, tree); extern void pushlevel_class (void); extern void poplevel_class (void); -extern tree pushdecl_with_scope (tree, cp_binding_level *, bool); extern tree lookup_name_prefer_type (tree, int); extern tree lookup_name_real (tree, int, int, bool, int, int); extern tree lookup_type_scope (tree, tag_scope);