A patch from the modules branch. I realized we don't need namespace
field to hold using directives. Each binding level already has such a
field, and we can easily go from namespace decl to its binding level.
This patch removes the usings field, and adjusts the accesses in
name-lookup. As another benefit the diagnostic machinery looking for
using namespace std is simplified.
Applying to trunk.
nathan
--
Nathan Sidwell
2019-05-20 Nathan Sidwell <nat...@acm.org>
* cp-tree.h (struct lang_decl_ns): Remove usings field.
(DECL_NAMESPACE_USING): Delete.
* name-lookup.c (name_lookup::search_usings): Use namespace's
binding scope.
(name_lookup::queue_namespae): Likewise.
(finish_namespace_using_directive, push_namespace): Likewise.
(has_using_namespace_std_directive): Just search the entire
binding stack.
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h (revision 271412)
+++ gcc/cp/cp-tree.h (working copy)
@@ -2669,7 +2669,5 @@ struct GTY(()) lang_decl_ns {
cp_binding_level *level;
- /* using directives and inline children. These need to be va_gc,
- because of PCH. */
- vec<tree, va_gc> *usings;
+ /* Inline children. These need to be va_gc, because of PCH. */
vec<tree, va_gc> *inlinees;
@@ -3260,8 +3258,4 @@ struct GTY(()) lang_decl {
TREE_LANG_FLAG_0 (NAMESPACE_DECL_CHECK (NODE))
-/* In a NAMESPACE_DECL, a vector of using directives. */
-#define DECL_NAMESPACE_USING(NODE) \
- (LANG_DECL_NS_CHECK (NODE)->usings)
-
/* In a NAMESPACE_DECL, a vector of inline namespaces. */
#define DECL_NAMESPACE_INLINEES(NODE) \
Index: gcc/cp/name-lookup.c
===================================================================
--- gcc/cp/name-lookup.c (revision 271412)
+++ gcc/cp/name-lookup.c (working copy)
@@ -590,5 +590,5 @@ name_lookup::search_usings (tree scope)
bool found = false;
- if (vec<tree, va_gc> *usings = DECL_NAMESPACE_USING (scope))
+ if (vec<tree, va_gc> *usings = NAMESPACE_LEVEL (scope)->using_directives)
for (unsigned ix = usings->length (); ix--;)
found |= search_qualified ((*usings)[ix], true);
@@ -652,5 +652,5 @@ name_lookup::queue_namespace (using_queu
/* Queue its using targets. */
- queue = queue_usings (queue, depth, DECL_NAMESPACE_USING (scope));
+ queue = queue_usings (queue, depth, NAMESPACE_LEVEL (scope)->using_directives);
return queue;
@@ -5273,19 +5273,9 @@ has_using_namespace_std_directive_p ()
/* Look at local using-directives. */
for (cp_binding_level *level = current_binding_level;
- level->kind != sk_namespace;
+ level;
level = level->level_chain)
if (using_directives_contain_std_p (level->using_directives))
return true;
- /* Look at this namespace and its ancestors. */
- for (tree scope = current_namespace; scope; scope = CP_DECL_CONTEXT (scope))
- {
- if (using_directives_contain_std_p (DECL_NAMESPACE_USING (scope)))
- return true;
-
- if (scope == global_namespace)
- break;
- }
-
return false;
}
@@ -7254,5 +7244,5 @@ finish_namespace_using_directive (tree t
return;
- add_using_namespace (DECL_NAMESPACE_USING (current_namespace),
+ add_using_namespace (current_binding_level->using_directives,
ORIGINAL_NAMESPACE (target));
emit_debug_info_using_namespace (current_namespace,
@@ -7405,5 +7395,5 @@ push_namespace (tree name, bool make_inl
if (!make_inline)
- add_using_namespace (DECL_NAMESPACE_USING (current_namespace),
+ add_using_namespace (current_binding_level->using_directives,
ns);
}