]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: correct object scope handling
authorJason Merrill <jason@redhat.com>
Mon, 13 Sep 2021 20:10:09 +0000 (16:10 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 15 Sep 2021 04:05:33 +0000 (00:05 -0400)
The way cp_parser_lookup_name handles object scope (i.e. the scope on the
RHS of a . or -> expression) is a bit subtle: before the lookup it's in
parser->context->object type, and after the lookup it's in
parser->object_scope.  But a couple of places that elide lookups were
failing to do the same transform.

I'm not aware of this breaking anything currently.

gcc/cp/ChangeLog:

* parser.c (cp_parser_template_name): Move object type.
(cp_parser_pre_parsed_nested_name_specifier): Likewise.

gcc/cp/parser.c

index ab1dc81b99705d298ad17838a9d0bcc495cbaf85..7a0b62343509ba040b15877e093fca01f4a061fb 100644 (file)
@@ -18405,6 +18405,7 @@ cp_parser_template_name (cp_parser* parser,
            {
              /* We're optimizing away the call to cp_parser_lookup_name, but
                 we still need to do this.  */
+             parser->object_scope = parser->context->object_type;
              parser->context->object_type = NULL_TREE;
              return identifier;
            }
@@ -33575,7 +33576,8 @@ cp_parser_pre_parsed_nested_name_specifier (cp_parser *parser)
   /* Set the scope from the stored value.  */
   parser->scope = saved_checks_value (check_value);
   parser->qualifying_scope = check_value->qualifying_scope;
-  parser->object_scope = NULL_TREE;
+  parser->object_scope = parser->context->object_type;
+  parser->context->object_type = NULL_TREE;
 }
 
 /* Consume tokens up through a non-nested END token.  Returns TRUE if we