aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r--gcc/cp/parser.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 2193bac..fa41ce6 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -1831,7 +1831,7 @@ static void cp_parser_label_declaration
/* 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
@@ -2905,7 +2905,18 @@ cp_parser_primary_expression (cp_parser *parser,
/* 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. */
@@ -8331,7 +8342,8 @@ cp_parser_type_parameter (cp_parser* parser)
/*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);
@@ -8710,7 +8722,8 @@ cp_parser_template_name (cp_parser* parser,
/*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. */
@@ -8900,7 +8913,8 @@ cp_parser_template_argument (cp_parser* parser)
/*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");
@@ -9753,7 +9767,8 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
/*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
@@ -10029,7 +10044,8 @@ cp_parser_namespace_name (cp_parser* parser)
/*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)
@@ -12239,7 +12255,8 @@ cp_parser_class_name (cp_parser *parser,
type_p,
/*is_template=*/false,
/*is_namespace=*/false,
- check_dependency_p);
+ check_dependency_p,
+ /*ambiguous_p=*/NULL);
}
}
else
@@ -14121,16 +14138,24 @@ cp_parser_label_declaration (cp_parser* parser)
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. */
@@ -14278,6 +14303,8 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
/* 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))
@@ -14319,7 +14346,8 @@ cp_parser_lookup_name_simple (cp_parser* parser, tree name)
/*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