This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix PR 13728


This is the missing diagnostic for

void f (int fred, int fred) 

and a missing diagnostic is precisely what it is.  Simply a case that
fell through the cracks when I split up duplicate_decls.

Fixed thus; bootstrapped i686-linux, applied mainline and 3.4
branch.

        PR 13728
        * c-decl.c (diagnose_mismatched_decls): Issue an error for two
        parameters with the same name, unless one is a forward decl.
        Do not issue a redundant-redeclaration warning for forward
        decls of parameters.
        * gcc.dg/decl-4.c: New testcase.

===================================================================
Index: c-decl.c
--- c-decl.c	27 Feb 2004 07:09:36 -0000	1.481
+++ c-decl.c	4 Mar 2004 05:45:23 -0000
@@ -1211,8 +1211,18 @@ diagnose_mismatched_decls (tree newdecl,
 	    }
 	}
     }
-  else /* VAR_DECL */
+  else /* PARM_DECL, VAR_DECL */
     {
+      /* Redeclaration of a PARM_DECL is invalid unless this is the
+	 real position of a forward-declared parameter (GCC extension).  */
+      if (TREE_CODE (newdecl) == PARM_DECL
+	  && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl)))
+	{
+	  error ("%Jredefinition of parameter '%D'", newdecl, newdecl);
+	  locate_old_decl (olddecl, error);
+	  return false;
+	}
+
       /* These bits are only type qualifiers when applied to objects.  */
       if (TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl))
 	{
@@ -1241,10 +1251,13 @@ diagnose_mismatched_decls (tree newdecl,
       && warn_redundant_decls
       /* Don't warn about a function declaration followed by a
 	 definition.  */
-    && !(TREE_CODE (newdecl) == FUNCTION_DECL
-	 && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
-    /* Don't warn about an extern followed by a definition.  */
-    && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl)))
+      && !(TREE_CODE (newdecl) == FUNCTION_DECL
+	   && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
+      /* Don't warn about an extern followed by a definition.  */
+      && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl))
+      /* Don't warn about forward parameter decls.  */
+      && !(TREE_CODE (newdecl) == PARM_DECL
+	   && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl)))
     {
       warning ("%Jredundant redeclaration of '%D'", newdecl, newdecl);
       warned = true;
===================================================================
Index: testsuite/gcc.dg/decl-4.c
--- testsuite/gcc.dg/decl-4.c	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/decl-4.c	4 Mar 2004 05:45:24 -0000
@@ -0,0 +1,10 @@
+/* Redeclaration of parameters is an error.  PR 13728.  */
+/* { dg-do compile } */
+
+void f (int fred,	/* { dg-error "previous definition" "" } */
+	int fred);	/* { dg-error "redefinition of parameter" "" } */
+
+void f2 (int fred,	/* { dg-error "previous definition" "" } */
+	 int fred)	/* { dg-error "redefinition of parameter" "" } */
+{
+}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]