From a3a503a57298d397b65d9e9599e1c0e5db552858 Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Sun, 25 Jan 2004 22:43:08 +0000 Subject: [PATCH] re PR c++/13810 (ICE on invalid default templates) PR c++/13810 * parser.c (cp_parser_type_parameter): When cp_parser_id_expression returns a TYPE_DECL. no further lookup is required. * semantics.c (check_template_template_default_arg): A TYPE_DECL is invalid. Rework to give better diagnostics. From-SVN: r76593 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/parser.c | 24 +++++++++++++++--------- gcc/cp/semantics.c | 18 ++++++++++++++++-- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 904738196f6..5171c70f963 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2004-01-25 Giovanni Bajo + + PR c++/13810 + * parser.c (cp_parser_type_parameter): When cp_parser_id_expression + returns a TYPE_DECL. no further lookup is required. + * semantics.c (check_template_template_default_arg): A TYPE_DECL + is invalid. Rework to give better diagnostics. + 2004-01-25 Kriang Lerdsuwanakij PR c++/13797 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 4fde7b64a51..0ca1dca56a8 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -7708,13 +7708,19 @@ cp_parser_type_parameter (cp_parser* parser) /*check_dependency_p=*/true, /*template_p=*/&is_template, /*declarator_p=*/false); - /* Look up the name. */ - default_argument - = cp_parser_lookup_name (parser, default_argument, - /*is_type=*/false, - /*is_template=*/is_template, - /*is_namespace=*/false, - /*check_dependency=*/true); + 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, + /*is_type=*/false, + /*is_template=*/is_template, + /*is_namespace=*/false, + /*check_dependency=*/true); /* See if the default argument is valid. */ default_argument = check_template_template_default_arg (default_argument); @@ -12705,8 +12711,8 @@ cp_parser_base_specifier (cp_parser* parser) break; } } - /* It is not uncommon to see programs mechanically, errouneously, use - the 'typename' keyword to denote (dependent) qualified types + /* It is not uncommon to see programs mechanically, errouneously, use + the 'typename' keyword to denote (dependent) qualified types as base classes. */ if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TYPENAME)) { diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 059ed1591e5..3cf4e08fca6 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1942,10 +1942,24 @@ check_template_template_default_arg (tree argument) { if (TREE_CODE (argument) != TEMPLATE_DECL && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM - && TREE_CODE (argument) != TYPE_DECL && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE) { - error ("invalid default template argument"); + if (TREE_CODE (argument) == TYPE_DECL) + { + tree t = TREE_TYPE (argument); + + /* Try to emit a slightly smarter error message if we detect + that the user is using a template instantiation. */ + if (CLASSTYPE_TEMPLATE_INFO (t) + && CLASSTYPE_TEMPLATE_INSTANTIATION (t)) + error ("invalid use of type `%T' as a default value for a " + "template template-parameter", t); + else + error ("invalid use of `%D' as a default value for a template " + "template-parameter", argument); + } + else + error ("invalid default argument for a template template parameter"); return error_mark_node; } -- 2.30.2