From: Andrew Sutton Date: Thu, 9 Jul 2015 17:50:06 +0000 (+0000) Subject: * parser.c (cp_parser_default_type_template_argument) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2cc6d90e2d74a1bd0f97bf7106a86c1b85f70d8f;p=gcc.git * parser.c (cp_parser_default_type_template_argument) (cp_parser_default_template_template_argument): Factor out from cp_parser_type_parameter. From-SVN: r225620 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c1a85e5c730..de571666acb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-07-09 Andrew Sutton + + * parser.c (cp_parser_default_type_template_argument) + (cp_parser_default_template_template_argument): Factor out from + cp_parser_type_parameter. + 2015-07-09 Paolo Carlini * typeck.c (warn_args_num): Rename to error_args_num. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index d64b22711a5..686654cd843 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -13330,6 +13330,69 @@ cp_parser_template_parameter_list (cp_parser* parser) return end_template_parm_list (parameter_list); } +/* Parse a default argument for a type template-parameter. + Note that diagnostics are handled in cp_parser_template_parameter. */ + +static tree +cp_parser_default_type_template_argument (cp_parser *parser) +{ + gcc_assert (cp_lexer_next_token_is (parser->lexer, CPP_EQ)); + + /* Consume the `=' token. */ + cp_lexer_consume_token (parser->lexer); + + /* Parse the default-argument. */ + push_deferring_access_checks (dk_no_deferred); + tree default_argument = cp_parser_type_id (parser); + pop_deferring_access_checks (); + + return default_argument; +} + +/* Parse a default argument for a template template-parameter. */ + +static tree +cp_parser_default_template_template_argument (cp_parser *parser) +{ + gcc_assert (cp_lexer_next_token_is (parser->lexer, CPP_EQ)); + + bool is_template; + + /* Consume the `='. */ + cp_lexer_consume_token (parser->lexer); + /* Parse the id-expression. */ + push_deferring_access_checks (dk_no_deferred); + /* save token before parsing the id-expression, for error + reporting */ + const cp_token* token = cp_lexer_peek_token (parser->lexer); + tree default_argument + = cp_parser_id_expression (parser, + /*template_keyword_p=*/false, + /*check_dependency_p=*/true, + /*template_p=*/&is_template, + /*declarator_p=*/false, + /*optional_p=*/false); + if (TREE_CODE (default_argument) == TYPE_DECL) + /* If the id-expression was a template-id that refers to + a template-class, we already have the declaration here, + so no further lookup is needed. */ + ; + else + /* Look up the name. */ + default_argument + = cp_parser_lookup_name (parser, default_argument, + none_type, + /*is_template=*/is_template, + /*is_namespace=*/false, + /*check_dependency=*/true, + /*ambiguous_decls=*/NULL, + token->location); + /* See if the default argument is valid. */ + default_argument = check_template_template_default_arg (default_argument); + pop_deferring_access_checks (); + return default_argument; +} + /* Parse a template-parameter. template-parameter: @@ -13552,11 +13615,8 @@ cp_parser_type_parameter (cp_parser* parser, bool *is_parameter_pack) /* If the next token is an `=', we have a default argument. */ if (cp_lexer_next_token_is (parser->lexer, CPP_EQ)) { - /* Consume the `=' token. */ - cp_lexer_consume_token (parser->lexer); - /* Parse the default-argument. */ - push_deferring_access_checks (dk_no_deferred); - default_argument = cp_parser_type_id (parser); + default_argument + = cp_parser_default_type_template_argument (parser); /* Template parameter packs cannot have default arguments. */ @@ -13574,7 +13634,6 @@ cp_parser_type_parameter (cp_parser* parser, bool *is_parameter_pack) } else if (check_for_bare_parameter_packs (default_argument)) default_argument = error_mark_node; - pop_deferring_access_checks (); } else default_argument = NULL_TREE; @@ -13632,40 +13691,8 @@ cp_parser_type_parameter (cp_parser* parser, bool *is_parameter_pack) default-argument. */ if (cp_lexer_next_token_is (parser->lexer, CPP_EQ)) { - bool is_template; - - /* Consume the `='. */ - cp_lexer_consume_token (parser->lexer); - /* Parse the id-expression. */ - push_deferring_access_checks (dk_no_deferred); - /* save token before parsing the id-expression, for error - reporting */ - token = cp_lexer_peek_token (parser->lexer); - default_argument - = cp_parser_id_expression (parser, - /*template_keyword_p=*/false, - /*check_dependency_p=*/true, - /*template_p=*/&is_template, - /*declarator_p=*/false, - /*optional_p=*/false); - if (TREE_CODE (default_argument) == TYPE_DECL) - /* If the id-expression was a template-id that refers to - a template-class, we already have the declaration here, - so no further lookup is needed. */ - ; - else - /* Look up the name. */ - default_argument - = cp_parser_lookup_name (parser, default_argument, - none_type, - /*is_template=*/is_template, - /*is_namespace=*/false, - /*check_dependency=*/true, - /*ambiguous_decls=*/NULL, - token->location); - /* See if the default argument is valid. */ default_argument - = check_template_template_default_arg (default_argument); + = cp_parser_default_template_template_argument (parser); /* Template parameter packs cannot have default arguments. */ @@ -13681,7 +13708,6 @@ cp_parser_type_parameter (cp_parser* parser, bool *is_parameter_pack) "have default arguments"); default_argument = NULL_TREE; } - pop_deferring_access_checks (); } else default_argument = NULL_TREE;