cp-tree.h: Declare.
authorBenjamin Kosnik <bkoz@gcc.gnu.org>
Mon, 24 Aug 1998 11:57:09 +0000 (11:57 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Mon, 24 Aug 1998 11:57:09 +0000 (11:57 +0000)

1998-08-24  Benjamin Kosnik  <bkoz@cygnus.com>
* cp-tree.h: Declare.
* pt.c (decl_template_parm_p): New function.
* decl.c (pushdecl): Check decls for redeclaring template parms.
(xref_tag): Make redeclaration an error, print decl.
* decl2.c (grokfield): Check field_decls for redeclaration as well.

From-SVN: r21943

gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/decl2.c

index 26e39a9..b73fb53 100644 (file)
@@ -2837,6 +2837,7 @@ extern int more_specialized_class         PROTO((tree, tree));
 extern void do_pushlevel                       PROTO((void));
 extern int is_member_template                   PROTO((tree));
 extern int comp_template_parms                  PROTO((tree, tree));
+extern int decl_template_parm_p                        PROTO((tree));
 extern int template_class_depth                 PROTO((tree));
 extern int is_specialization_of                 PROTO((tree, tree));
 extern int comp_template_args                   PROTO((tree, tree));
index 8c3a32b..f232fdd 100644 (file)
@@ -3669,6 +3669,16 @@ pushdecl (x)
              if (warnstring)
                warning (warnstring, IDENTIFIER_POINTER (name));
            }
+         /* Check to see if decl redeclares a template parameter. */
+         if (oldlocal && (current_class_type || current_function_decl ) 
+             && current_template_parms)
+           {
+             if (decl_template_parm_p (oldlocal))
+               {
+                 cp_error ("redeclaration of template parameter `%T'", name);
+                 cp_error_at (" previously declared here `%#D'", oldlocal);
+               }
+           }
        }
 
       if (TREE_CODE (x) == FUNCTION_DECL)
@@ -11480,11 +11490,12 @@ xref_tag (code_type_node, name, binfo, globalize)
 
   if (! globalize)
     {
-      if (pedantic && t && (TREE_CODE (t) == TEMPLATE_TYPE_PARM 
+      if (t && (TREE_CODE (t) == TEMPLATE_TYPE_PARM 
                            || TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM))
        {
-         cp_pedwarn ("redeclaration of template type-parameter `%T'", name);
-         cp_pedwarn_at ("  previously declared here", t);
+         cp_error ("redeclaration of template type-parameter `%T'", name);
+         cp_error_at ("  previously declared here `%#D'", 
+                      TEMPLATE_TYPE_DECL (t));
        }
       if (t && TYPE_CONTEXT (t) && got_type)
        ref = t;
index 9333d8d..b8c4370 100644 (file)
@@ -1761,6 +1761,19 @@ grokfield (declarator, declspecs, init, asmspec_tree, attrlist)
       && (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == FUNCTION_DECL))
     value = push_template_decl (value);
 
+  /* Check to see if a field redeclares a template parameter. */
+  if (current_template_parms 
+      && TREE_CODE (declarator) == IDENTIFIER_NODE
+      && IDENTIFIER_LOCAL_VALUE (declarator))
+      {
+       tree olddecl = IDENTIFIER_LOCAL_VALUE (declarator);
+       if (decl_template_parm_p (olddecl))
+         {
+           cp_error ("redeclaration of template parameter `%T'", declarator);
+           cp_error_at (" previously declared here `%#D'", olddecl);
+         }
+      }
+
   if (attrlist)
     cplus_decl_attributes (value, TREE_PURPOSE (attrlist),
                           TREE_VALUE (attrlist));