pt.c (push_template_decl_real): Complain about default template args for enclosing...
authorJason Merrill <jason@yorick.cygnus.com>
Wed, 28 Oct 1998 02:33:00 +0000 (02:33 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 28 Oct 1998 02:33:00 +0000 (21:33 -0500)
* pt.c (push_template_decl_real): Complain about default template
args for enclosing classes.

From-SVN: r23389

gcc/cp/ChangeLog
gcc/cp/pt.c

index b47514b0563fb49c5c840141e0bf107672ba253c..c1bb9044fcd7ef15858fbcca00c0e14511ea2b7b 100644 (file)
@@ -1,5 +1,8 @@
 1998-10-28  Jason Merrill  <jason@yorick.cygnus.com>
 
+       * pt.c (push_template_decl_real): Complain about default template
+       args for enclosing classes.
+
        * call.c (add_function_candidate): Treat conversion functions
        as coming from the argument's class.
        * cp-tree.h (DECL_CONV_FN_P): New fn.
index c0726b74e9ab355a277132227578f148b861d75a..12ff5260076804bd0e28a840477be6bdaba5bd12 100644 (file)
@@ -2102,6 +2102,42 @@ push_template_decl_real (decl, is_friend)
       && CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (decl)))
     return process_partial_specialization (decl);
 
+  /* [temp.param] A default template-argument shall not be specified in a
+     function template declaration or a function template definition, nor
+     in the template-parameter-list of the definition of a member of a
+     class template.  */
+  {
+    tree parms;
+    int issued_default_arg_message = 0;
+
+    parms = current_template_parms;
+    if (primary)
+      parms = TREE_CHAIN (parms);
+    for (; parms; parms = TREE_CHAIN (parms))
+      {
+       tree inner_parms = TREE_VALUE (parms);
+       int i, ntparms;
+
+       if (TREE_TYPE (inner_parms))
+         continue;
+
+       ntparms = TREE_VEC_LENGTH (inner_parms);
+       for (i = 0; i < ntparms; ++i) 
+         {
+           if (TREE_PURPOSE (TREE_VEC_ELT (inner_parms, i)))
+             {
+               if (!issued_default_arg_message)
+                 {
+                   cp_error ("default argument for template parameter of class enclosing `%D'", 
+                             decl);
+                   issued_default_arg_message = 1;
+                 }
+               TREE_PURPOSE (TREE_VEC_ELT (inner_parms, i)) = NULL_TREE;
+             }
+         }
+      }
+  }
+
   args = current_template_args ();
 
   if (!ctx