name_lookup lookup (name, 0);
if (!lookup.search_qualified (current_namespace, /*usings=*/false))
;
- else if (TREE_CODE (lookup.value) != NAMESPACE_DECL)
- ;
- else if (tree dna = DECL_NAMESPACE_ALIAS (lookup.value))
+ else if (TREE_CODE (lookup.value) == TREE_LIST)
{
- /* A namespace alias is not allowed here, but if the alias
- is for a namespace also inside the current scope,
- accept it with a diagnostic. That's better than dying
- horribly. */
- if (is_nested_namespace (current_namespace, CP_DECL_CONTEXT (dna)))
+ /* An ambiguous lookup. If exactly one is a namespace, we
+ want that. If more than one is a namespace, error, but
+ pick one of them. */
+ /* DR2061 can cause us to find multiple namespaces of the same
+ name. We must treat that carefully and avoid thinking we
+ need to push a new (possibly) duplicate namespace. Hey,
+ if you want to use the same identifier within an inline
+ nest, knock yourself out. */
+ for (tree *chain = &lookup.value, next; (next = *chain);)
+ {
+ tree decl = TREE_VALUE (next);
+ if (TREE_CODE (decl) == NAMESPACE_DECL)
+ {
+ if (!ns)
+ ns = decl;
+ else if (SCOPE_DEPTH (ns) >= SCOPE_DEPTH (decl))
+ ns = decl;
+
+ /* Advance. */
+ chain = &TREE_CHAIN (next);
+ }
+ else
+ /* Stitch out. */
+ *chain = TREE_CHAIN (next);
+ }
+
+ if (TREE_CHAIN (lookup.value))
{
- error ("namespace alias %qD not allowed here, "
- "assuming %qD", lookup.value, dna);
- ns = dna;
+ error ("%<namespace %E%> is ambiguous", name);
+ print_candidates (lookup.value);
}
}
- else
+ else if (TREE_CODE (lookup.value) == NAMESPACE_DECL)
ns = lookup.value;
+
+ if (ns)
+ if (tree dna = DECL_NAMESPACE_ALIAS (ns))
+ {
+ /* A namespace alias is not allowed here, but if the alias
+ is for a namespace also inside the current scope,
+ accept it with a diagnostic. That's better than dying
+ horribly. */
+ if (is_nested_namespace (current_namespace, CP_DECL_CONTEXT (dna)))
+ {
+ error ("namespace alias %qD not allowed here, "
+ "assuming %qD", ns, dna);
+ ns = dna;
+ }
+ else
+ ns = NULL_TREE;
+ }
}
bool new_ns = false;