+2017-05-11 Nathan Sidwell <nathan@acm.org>
+
+ * name-lookup.h (pop_binding): Rename to pop_local_binding.
+ (getdecls): Rename to get_local_decls.
+ * name-lookup.c (pop_binding): Rename to ...
+ (pop_local_binding): ... here.
+ (pop_bindings_and_leave_scope): Adjust.
+ (getdecls): Rename to ...
+ (get_local_decls): ... here. Assert local scope.
+ * decl.c (poplevel): Assert not namespace. Adjust and simplify
+ logic.
+ (store_parm_decls): Adjust get_local_decls call.
+ (parser.c (synthesize_implicit_template_parm): Likewise.
+
2017-05-11 Ville Voutilainen <ville.voutilainen@gmail.com>
PR c++/80682
block = NULL_TREE;
- gcc_assert (current_binding_level->kind != sk_class);
+ gcc_assert (current_binding_level->kind != sk_class
+ && current_binding_level->kind != sk_namespace);
if (current_binding_level->kind == sk_cleanup)
functionbody = 0;
if ((warn_unused_variable || warn_unused_but_set_variable)
&& current_binding_level->kind != sk_template_parms
&& !processing_template_decl)
- for (tree d = getdecls (); d; d = TREE_CHAIN (d))
+ for (tree d = get_local_decls (); d; d = TREE_CHAIN (d))
{
/* There are cases where D itself is a TREE_LIST. See in
push_local_binding where the list of decls returned by
getdecls is built. */
decl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
+
tree type = TREE_TYPE (decl);
if (VAR_P (decl)
&& (! TREE_USED (decl) || !DECL_READ_P (decl))
/* Remove declarations for all the DECLs in this level. */
for (link = decls; link; link = TREE_CHAIN (link))
{
- if (leaving_for_scope && VAR_P (link)
+ decl = TREE_CODE (link) == TREE_LIST ? TREE_VALUE (link) : link;
+ tree name = DECL_NAME (OVL_CURRENT (decl));
+
+ if (leaving_for_scope && VAR_P (decl)
/* It's hard to make this ARM compatibility hack play nicely with
lambdas, and it really isn't necessary in C++11 mode. */
&& cxx_dialect < cxx11
- && DECL_NAME (link))
+ && name)
{
- tree name = DECL_NAME (link);
-
cxx_binding *ob = outer_binding (name,
IDENTIFIER_BINDING (name),
/*class_p=*/true);
and we are leaving the `for' scope. There's no reason to
keep the binding of the inner `i' in this case. */
- pop_binding (name, link);
+ ;
else if ((ob && (TREE_CODE (ob->value) == TYPE_DECL))
|| (ns_binding && TREE_CODE (ns_binding) == TYPE_DECL))
/* Here, we have something like:
We must pop the for-scope binding so we know what's a
type and what isn't. */
- pop_binding (name, link);
+ ;
else
{
/* Mark this VAR_DECL as dead so that we can tell we left it
its SCOPE since the scope is going away now. */
IDENTIFIER_BINDING (name)->scope
= current_binding_level->level_chain;
- }
- }
- else
- {
- tree name;
-
- /* Remove the binding. */
- decl = link;
- if (TREE_CODE (decl) == TREE_LIST)
- decl = TREE_VALUE (decl);
- name = decl;
-
- if (TREE_CODE (name) == OVERLOAD)
- name = OVL_FUNCTION (name);
-
- gcc_assert (DECL_P (name));
- pop_binding (DECL_NAME (name), decl);
+ /* Don't remove the binding. */
+ name = NULL_TREE;
+ }
}
+ /* Remove the binding. */
+ pop_local_binding (name, decl);
}
/* Remove declarations for any `for' variables from inner scopes
that we kept around. */
FOR_EACH_VEC_SAFE_ELT_REVERSE (current_binding_level->dead_vars_from_for,
ix, decl)
- pop_binding (DECL_NAME (decl), decl);
+ pop_local_binding (DECL_NAME (decl), decl);
/* Restore the IDENTIFIER_TYPE_VALUEs. */
for (link = current_binding_level->type_shadowed;
/* Get the decls in their original chain order and record in the
function. This is all and only the PARM_DECLs that were
pushed into scope by the loop above. */
- DECL_ARGUMENTS (fndecl) = getdecls ();
+ DECL_ARGUMENTS (fndecl) = get_local_decls ();
}
else
DECL_ARGUMENTS (fndecl) = NULL_TREE;
for ID. */
void
-pop_binding (tree id, tree decl)
+pop_local_binding (tree id, tree decl)
{
cxx_binding *binding;
void
pop_bindings_and_leave_scope (void)
{
- for (tree t = getdecls (); t; t = DECL_CHAIN (t))
- pop_binding (DECL_NAME (t), t);
+ for (tree t = get_local_decls (); t; t = DECL_CHAIN (t))
+ pop_local_binding (DECL_NAME (t), t);
leave_scope ();
}
keep_next_level_flag = keep;
}
-/* Return the list of declarations of the current level.
- Note that this list is in reverse order unless/until
- you nreverse it; and when you do nreverse it, you must
- store the result back using `storedecls' or you will lose. */
+/* Return the list of declarations of the current local scope. */
tree
-getdecls (void)
+get_local_decls (void)
{
+ gcc_assert (current_binding_level->kind != sk_namespace
+ && current_binding_level->kind != sk_class);
return current_binding_level->names;
}
extern tree identifier_type_value (tree);
extern void set_identifier_type_value (tree, tree);
extern void push_binding (tree, tree, cp_binding_level*);
-extern void pop_binding (tree, tree);
+extern void pop_local_binding (tree, tree);
extern void pop_bindings_and_leave_scope (void);
extern tree constructor_name (tree);
extern bool constructor_name_p (tree, tree);
extern bool pushdecl_class_level (tree);
extern tree pushdecl_namespace_level (tree, bool);
extern bool push_class_level_binding (tree, tree);
-extern tree getdecls (void);
+extern tree get_local_decls ();
extern int function_parm_depth (void);
extern tree cp_namespace_decls (tree);
extern void set_decl_namespace (tree, tree, bool);