aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiovanni Bajo <giovannibajo@gcc.gnu.org>2004-01-25 22:43:08 +0000
committerGiovanni Bajo <giovannibajo@gcc.gnu.org>2004-01-25 22:43:08 +0000
commita3a503a57298d397b65d9e9599e1c0e5db552858 (patch)
tree2c5d5e1c3409aad85f5a549b959cd599fbaff44f
parent91eab3788d093dab188305f7d0befb813b310824 (diff)
downloadgcc-a3a503a57298d397b65d9e9599e1c0e5db552858.zip
gcc-a3a503a57298d397b65d9e9599e1c0e5db552858.tar.gz
gcc-a3a503a57298d397b65d9e9599e1c0e5db552858.tar.bz2
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
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/parser.c24
-rw-r--r--gcc/cp/semantics.c18
3 files changed, 39 insertions, 11 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 9047381..5171c70 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2004-01-25 Giovanni Bajo <giovannibajo@gcc.gnu.org>
+
+ 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 <lerdsuwa@users.sourceforge.net>
PR c++/13797
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 4fde7b6..0ca1dca 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 059ed15..3cf4e08 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;
}