aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/parser.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2016-05-25 14:29:14 -0400
committerJason Merrill <jason@gcc.gnu.org>2016-05-25 14:29:14 -0400
commit1b22fc54fd4fe739ba2d223fc8f3e3b036beddf1 (patch)
tree0cd1bfde15477ae2028496320a01fa745b2ca052 /gcc/cp/parser.c
parent04080f22d657e9762500f5a7f6c9843ebfc46517 (diff)
downloadgcc-1b22fc54fd4fe739ba2d223fc8f3e3b036beddf1.zip
gcc-1b22fc54fd4fe739ba2d223fc8f3e3b036beddf1.tar.gz
gcc-1b22fc54fd4fe739ba2d223fc8f3e3b036beddf1.tar.bz2
PR c++/71173 - wrong qualified lookup
PR c++/70522 * cp-tree.h (enum tag_types): Add scope_type. * parser.c (cp_parser_class_name): Use scope_type. (prefer_type_arg): Handle scope_type. (cp_parser_lookup_name): Use prefer_type_arg. * name-lookup.c (lookup_qualified_name): Change bool is_type_p to int prefer_type, use lookup_flags. * name-lookup.h: Adjust. From-SVN: r236736
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r--gcc/cp/parser.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index d21230f..546aada 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -21190,7 +21190,7 @@ cp_parser_class_name (cp_parser *parser,
resolution operator, object, function, and enumerator
names are ignored. */
if (cp_lexer_next_token_is (parser->lexer, CPP_SCOPE))
- tag_type = typename_type;
+ tag_type = scope_type;
/* Look up the name. */
decl = cp_parser_lookup_name (parser, identifier,
tag_type,
@@ -24595,6 +24595,24 @@ cp_parser_nested_requirement (cp_parser *parser)
/* Support Functions */
+/* Return the appropriate prefer_type argument for lookup_name_real based on
+ tag_type and template_mem_access. */
+
+static inline int
+prefer_type_arg (tag_types tag_type, bool template_mem_access = false)
+{
+ /* DR 141: When looking in the current enclosing context for a template-name
+ after -> or ., only consider class templates. */
+ if (template_mem_access)
+ return 2;
+ switch (tag_type)
+ {
+ case none_type: return 0; // No preference.
+ case scope_type: return 1; // Type or namespace.
+ default: return 2; // Type only.
+ }
+}
+
/* Looks up NAME in the current scope, as given by PARSER->SCOPE.
NAME should have one of the representations used for an
id-expression. If NAME is the ERROR_MARK_NODE, the ERROR_MARK_NODE
@@ -24731,7 +24749,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
errors may be issued. Even if we rollback the current
tentative parse, those errors are valid. */
decl = lookup_qualified_name (parser->scope, name,
- tag_type != none_type,
+ prefer_type_arg (tag_type),
/*complain=*/true);
/* 3.4.3.1: In a lookup in which the constructor is an acceptable
@@ -24752,7 +24770,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
&& DECL_SELF_REFERENCE_P (decl)
&& same_type_p (DECL_CONTEXT (decl), parser->scope))
decl = lookup_qualified_name (parser->scope, ctor_identifier,
- tag_type != none_type,
+ prefer_type_arg (tag_type),
/*complain=*/true);
/* If we have a single function from a using decl, pull it out. */
@@ -24808,7 +24826,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
decl = lookup_member (object_type,
name,
/*protect=*/0,
- tag_type != none_type,
+ prefer_type_arg (tag_type),
tf_warning_or_error);
else
decl = NULL_TREE;
@@ -24816,7 +24834,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
if (!decl)
/* Look it up in the enclosing context. DR 141: When looking for a
template-name after -> or ., only consider class templates. */
- decl = lookup_name_real (name, tag_type != none_type || is_template,
+ decl = lookup_name_real (name, prefer_type_arg (tag_type, is_template),
/*nonclass=*/0,
/*block_p=*/true, is_namespace, 0);
if (object_type == unknown_type_node)
@@ -24828,7 +24846,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
}
else
{
- decl = lookup_name_real (name, tag_type != none_type,
+ decl = lookup_name_real (name, prefer_type_arg (tag_type),
/*nonclass=*/0,
/*block_p=*/true, is_namespace, 0);
parser->qualifying_scope = NULL_TREE;