+2004-08-17 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/16965
+ * cp-tree.h (qualified_name_lookup_error): Add parameter.
+ * name-lookup.c (do_class_using_decl): Restrict set of entities
+ passed to cp_emit_debug_info_for_using more carefully.
+ (lookup_qualified_name): Allow lookup_member to return sets of
+ ambiguous entries.
+ * parser.c (cp_parser_lookup_name): Add ambiguous_p parameter.
+ (cp_parser_primary_expression): Handle ambiguous lookups.
+ (cp_parser_template_name): Adjust use of cp_parser_lookup_name.
+ (cp_parser_template_argument): Likewise.
+ (cp_parser_elaborate_type_specifier): Likewise.
+ (cp_parser_namespace_name): Likewise.
+ (cp_parser_class_name): Likewise.
+ (cp_parser_lookup_name_simple): Likewise.
+ * pt.c (tsubst_qualified_id): Handle ambiguous results.
+ (tsubst_expr): Likewise.
+ * semantics.c (qualified_name_lookup_error): Add decl paramter.
+ For ambiguous lookups, print candidates.
+
2004-08-16 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/6749
extern tree finish_base_specifier (tree, tree, bool);
extern void finish_member_declaration (tree);
extern void check_multiple_declarators (void);
-extern void qualified_name_lookup_error (tree, tree);
+extern void qualified_name_lookup_error (tree, tree, tree);
extern tree finish_id_expression (tree, tree, tree,
cp_id_kind *, tree *,
bool, bool, bool *,
tree r;
r = lookup_qualified_name (scope, name, false, false);
- if (r && TREE_CODE (r) != ERROR_MARK)
+ if (r && (DECL_P (r) || TREE_CODE (r) == OVERLOAD))
cp_emit_debug_info_for_using (r, scope);
}
return value;
Returns a DECL (or OVERLOAD, or BASELINK) representing the
declaration found. If no suitable declaration can be found,
- ERROR_MARK_NODE is returned. Iif COMPLAIN is true and SCOPE is
+ ERROR_MARK_NODE is returned. If COMPLAIN is true and SCOPE is
neither a class-type nor a namespace a diagnostic is issued. */
tree
else if (is_aggr_type (scope, complain))
{
tree t;
- t = lookup_member (scope, name, 0, is_type_p);
+ t = lookup_member (scope, name, 2, is_type_p);
if (t)
return t;
}
/* Utility Routines */
static tree cp_parser_lookup_name
- (cp_parser *, tree, bool, bool, bool, bool);
+ (cp_parser *, tree, bool, bool, bool, bool, bool *);
static tree cp_parser_lookup_name_simple
(cp_parser *, tree);
static tree cp_parser_maybe_treat_template_as_class
/* Look up the name. */
else
{
- decl = cp_parser_lookup_name_simple (parser, id_expression);
+ bool ambiguous_p;
+
+ decl = cp_parser_lookup_name (parser, id_expression,
+ /*is_type=*/false,
+ /*is_template=*/false,
+ /*is_namespace=*/false,
+ /*check_dependency=*/true,
+ &ambiguous_p);
+ /* If the lookup was ambiguous, an error will already have
+ been issued. */
+ if (ambiguous_p)
+ return error_mark_node;
/* If name lookup gives us a SCOPE_REF, then the
qualifying scope was dependent. Just propagate the
name. */
/*is_type=*/false,
/*is_template=*/is_template,
/*is_namespace=*/false,
- /*check_dependency=*/true);
+ /*check_dependency=*/true,
+ /*ambiguous_p=*/NULL);
/* See if the default argument is valid. */
default_argument
= check_template_template_default_arg (default_argument);
/*is_type=*/false,
/*is_template=*/false,
/*is_namespace=*/false,
- check_dependency_p);
+ check_dependency_p,
+ /*ambiguous_p=*/NULL);
decl = maybe_get_template_decl_from_type_decl (decl);
/* If DECL is a template, then the name was a template-name. */
/*is_type=*/false,
/*is_template=*/template_p,
/*is_namespace=*/false,
- /*check_dependency=*/true);
+ /*check_dependency=*/true,
+ /*ambiguous_p=*/NULL);
if (TREE_CODE (argument) != TEMPLATE_DECL
&& TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
cp_parser_error (parser, "expected template-name");
/*is_type=*/true,
/*is_template=*/false,
/*is_namespace=*/false,
- /*check_dependency=*/true);
+ /*check_dependency=*/true,
+ /*ambiguous_p=*/NULL);
/* If we are parsing friend declaration, DECL may be a
TEMPLATE_DECL tree node here. However, we need to check
/*is_type=*/false,
/*is_template=*/false,
/*is_namespace=*/true,
- /*check_dependency=*/true);
+ /*check_dependency=*/true,
+ /*ambiguous_p=*/NULL);
/* If it's not a namespace, issue an error. */
if (namespace_decl == error_mark_node
|| TREE_CODE (namespace_decl) != NAMESPACE_DECL)
type_p,
/*is_template=*/false,
/*is_namespace=*/false,
- check_dependency_p);
+ check_dependency_p,
+ /*ambiguous_p=*/NULL);
}
}
else
are ignored.
If CHECK_DEPENDENCY is TRUE, names are not looked up in dependent
- types. */
+ types.
+
+ If AMBIGUOUS_P is non-NULL, it is set to true if name-lookup
+ results in an ambiguity, and false otherwise. */
static tree
cp_parser_lookup_name (cp_parser *parser, tree name,
bool is_type, bool is_template, bool is_namespace,
- bool check_dependency)
+ bool check_dependency,
+ bool *ambiguous_p)
{
tree decl;
tree object_type = parser->context->object_type;
+ /* Assume that the lookup will be unambiguous. */
+ if (ambiguous_p)
+ *ambiguous_p = false;
+
/* Now that we have looked up the name, the OBJECT_TYPE (if any) is
no longer valid. Note that if we are parsing tentatively, and
the parse fails, OBJECT_TYPE will be automatically restored. */
/* If it's a TREE_LIST, the result of the lookup was ambiguous. */
if (TREE_CODE (decl) == TREE_LIST)
{
+ if (ambiguous_p)
+ *ambiguous_p = true;
/* The error message we have to print is too complicated for
cp_parser_error, so we incorporate its actions directly. */
if (!cp_parser_simulate_error (parser))
/*is_type=*/false,
/*is_template=*/false,
/*is_namespace=*/false,
- /*check_dependency=*/true);
+ /*check_dependency=*/true,
+ /*ambiguous_p=*/NULL);
}
/* If DECL is a TEMPLATE_DECL that can be treated like a TYPE_DECL in
}
if (DECL_P (expr))
- check_accessibility_of_qualified_id (expr, /*object_type=*/NULL_TREE,
- scope);
-
- /* Remember that there was a reference to this entity. */
- if (DECL_P (expr))
- mark_used (expr);
+ {
+ check_accessibility_of_qualified_id (expr, /*object_type=*/NULL_TREE,
+ scope);
+ /* Remember that there was a reference to this entity. */
+ mark_used (expr);
+ }
+
+ if (expr == error_mark_node || TREE_CODE (expr) == TREE_LIST)
+ {
+ if (complain & tf_error)
+ qualified_name_lookup_error (scope,
+ TREE_OPERAND (qualified_id, 1),
+ expr);
+ return error_mark_node;
+ }
if (is_template)
expr = lookup_template_function (expr, template_args);
if (expr == error_mark_node && complain & tf_error)
- qualified_name_lookup_error (scope, TREE_OPERAND (qualified_id, 1));
+ qualified_name_lookup_error (scope, TREE_OPERAND (qualified_id, 1),
+ expr);
else if (TYPE_P (scope))
{
expr = (adjust_result_of_qualified_name_lookup
decl = lookup_qualified_name (scope, name,
/*is_type_p=*/false,
/*complain=*/false);
- if (decl == error_mark_node)
- qualified_name_lookup_error (scope, name);
+ if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST)
+ qualified_name_lookup_error (scope, name, decl);
else
do_local_using_decl (decl, scope, name);
}
args);
else
{
- qualified_name_lookup_error (TREE_TYPE (object), tmpl);
+ qualified_name_lookup_error (TREE_TYPE (object), tmpl,
+ member);
return error_mark_node;
}
}
error ("multiple declarators in template declaration");
}
-/* Issue a diagnostic that NAME cannot be found in SCOPE. */
+/* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is
+ what we found when we tried to do the lookup. */
void
-qualified_name_lookup_error (tree scope, tree name)
+qualified_name_lookup_error (tree scope, tree name, tree decl)
{
if (TYPE_P (scope))
{
if (!COMPLETE_TYPE_P (scope))
error ("incomplete type `%T' used in nested name specifier", scope);
+ else if (TREE_CODE (decl) == TREE_LIST)
+ {
+ error ("reference to `%T::%D' is ambiguous", scope, name);
+ print_candidates (decl);
+ }
else
error ("`%D' is not a member of `%T'", name, scope);
}
/* If the qualifying type is non-dependent (and the name
does not name a conversion operator to a dependent
type), issue an error. */
- qualified_name_lookup_error (scope, id_expression);
+ qualified_name_lookup_error (scope, id_expression, decl);
return error_mark_node;
}
else if (!scope)
+2004-08-17 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/16965
+ * g++.dg/parse/error17.C: New test.
+
2004-08-17 Dorit Naishlos <dorit@il.ibm.com>
* gcc.dg/vect: New directory for vectorizer tests.
--- /dev/null
+// PR c++/16965
+
+template <typename T> struct B {
+ static int Bar(T); // { dg-error "" }
+};
+struct D : B<int>, B<char> {};
+
+int i2 = D::Bar(2); // { dg-error "" }