https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Here we have "p->template A<T>::a()" but cp_parser_expression only parses the
"p->template A<T>" part, so we complain that a ; isn't following.
It's because cp_parser_template_name now considers the object scope:
16957 if (template_keyword_p)
16958 {
16959 tree scope = (parser->scope ? parser->scope
16960 : parser->context->object_type);
16961 if (scope && TYPE_P (scope)
16962 && (!CLASS_TYPE_P (scope)
16963 || (check_dependency_p && dependent_type_p (scope))))
16964 {
16965 /* We're optimizing away the call to cp_parser_lookup_name,
but
16966 we still need to do this. */
16967 parser->context->object_type = NULL_TREE;
16968 return identifier;
16969 }
16970 }
which here is unknown_type_node, signalling a type-dependent object:
7756 if (dependent_p)
7757 /* Tell cp_parser_lookup_name that there was an object, even though
it's
7758 type-dependent. */
7759 parser->context->object_type = unknown_type_node;
so now cp_parser_template_name returns identifier 'A', cp_parser_class_name
creates a TEMPLATE_ID_EXPR A<T>, but then
23735 decl = make_typename_type (scope, decl, tag_type, tf_error);
fails because scope is NULL -- we've used the object scope instead. We
probably have to look that up first.