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.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index e2afb3b..bea2f61 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -8186,9 +8186,15 @@ cp_parser_type_parameter (cp_parser* parser)
if (cp_lexer_next_token_is_not (parser->lexer, CPP_EQ)
&& cp_lexer_next_token_is_not (parser->lexer, CPP_GREATER)
&& cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
- identifier = cp_parser_identifier (parser);
+ {
+ identifier = cp_parser_identifier (parser);
+ /* Treat invalid names as if the parameter were nameless. */
+ if (identifier == error_mark_node)
+ identifier = NULL_TREE;
+ }
else
identifier = NULL_TREE;
+
/* Create the template parameter. */
parameter = finish_template_template_parm (class_type_node,
identifier);
@@ -8231,15 +8237,13 @@ cp_parser_type_parameter (cp_parser* parser)
/* Create the combined representation of the parameter and the
default argument. */
- parameter = build_tree_list (default_argument, parameter);
+ parameter = build_tree_list (default_argument, parameter);
}
break;
default:
- /* Anything else is an error. */
- cp_parser_error (parser,
- "expected %<class%>, %<typename%>, or %<template%>");
- parameter = error_mark_node;
+ gcc_unreachable ();
+ break;
}
return parameter;
@@ -14801,6 +14805,11 @@ cp_parser_single_declaration (cp_parser* parser,
cp_decl_specifier_seq decl_specifiers;
bool function_definition_p = false;
+ /* This function is only used when processing a template
+ declaration. */
+ gcc_assert (innermost_scope_kind () == sk_template_parms
+ || innermost_scope_kind () == sk_template_spec);
+
/* Defer access checks until we know what is being declared. */
push_deferring_access_checks (dk_deferred);
@@ -14812,6 +14821,14 @@ cp_parser_single_declaration (cp_parser* parser,
&declares_class_or_enum);
if (friend_p)
*friend_p = cp_parser_friend_p (&decl_specifiers);
+
+ /* There are no template typedefs. */
+ if (decl_specifiers.specs[(int) ds_typedef])
+ {
+ error ("template declaration of %qs", "typedef");
+ decl = error_mark_node;
+ }
+
/* Gather up the access checks that occurred the
decl-specifier-seq. */
stop_deferring_access_checks ();
@@ -14843,8 +14860,6 @@ cp_parser_single_declaration (cp_parser* parser,
decl = error_mark_node;
}
}
- else
- decl = NULL_TREE;
/* If it's not a template class, try for a template function. If
the next token is a `;', then this declaration does not declare
anything. But, if there were errors in the decl-specifiers, then
@@ -14869,7 +14884,8 @@ cp_parser_single_declaration (cp_parser* parser,
parser->object_scope = NULL_TREE;
/* Look for a trailing `;' after the declaration. */
if (!function_definition_p
- && !cp_parser_require (parser, CPP_SEMICOLON, "`;'"))
+ && (decl == error_mark_node
+ || !cp_parser_require (parser, CPP_SEMICOLON, "`;'")))
cp_parser_skip_to_end_of_block_or_statement (parser);
return decl;