OSDN Git Service

PR c++/13810
authorgiovannibajo <giovannibajo@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 25 Jan 2004 22:43:08 +0000 (22:43 +0000)
committergiovannibajo <giovannibajo@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 25 Jan 2004 22:43:08 +0000 (22:43 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@76593 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/cp/semantics.c

index 9047381..5171c70 100644 (file)
@@ -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
index 4fde7b6..0ca1dca 100644 (file)
@@ -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\r
-     the 'typename' keyword to denote (dependent) qualified types\r
+  /* 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))
     {
index 059ed15..3cf4e08 100644 (file)
@@ -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;
     }