return cp_parser_make_typename_type (parser, parser->scope,
identifier,
token->location);
+
+ /* Template parameter lists apply only if we are not within a
+ function parameter list. */
+ bool template_parm_lists_apply
+ = parser->num_template_parameter_lists;
+ if (template_parm_lists_apply)
+ for (cp_binding_level *s = current_binding_level;
+ s && s->kind != sk_template_parms;
+ s = s->level_chain)
+ if (s->kind == sk_function_parms)
+ template_parm_lists_apply = false;
+
/* Look up a qualified name in the usual way. */
if (parser->scope)
{
decl = (cp_parser_maybe_treat_template_as_class
(decl, /*tag_name_p=*/is_friend
- && parser->num_template_parameter_lists));
+ && template_parm_lists_apply));
if (TREE_CODE (decl) != TYPE_DECL)
{
if (TREE_CODE (TREE_TYPE (decl)) != TYPENAME_TYPE)
{
- bool allow_template = (parser->num_template_parameter_lists
- || DECL_SELF_REFERENCE_P (decl));
- type = check_elaborated_type_specifier (tag_type, decl,
+ bool allow_template = (template_parm_lists_apply
+ || DECL_SELF_REFERENCE_P (decl));
+ type = check_elaborated_type_specifier (tag_type, decl,
allow_template);
if (type == error_mark_node)
ts = ts_global;
template_p =
- (parser->num_template_parameter_lists
+ (template_parm_lists_apply
&& (cp_parser_next_token_starts_class_definition_p (parser)
|| cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)));
/* An unqualified name was used to reference this type, so
there were no qualifying templates. */
- if (!cp_parser_check_template_parameters (parser,
- /*num_templates=*/0,
- token->location,
- /*declarator=*/NULL))
+ if (template_parm_lists_apply
+ && !cp_parser_check_template_parameters (parser,
+ /*num_templates=*/0,
+ token->location,
+ /*declarator=*/NULL))
return error_mark_node;
type = xref_tag (tag_type, identifier, ts, template_p);
}