This is the mail archive of the 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]

Re: [PATCH] -Wredundant-decls, do not warn for static forward decl

On Wed, Aug 31, 2005 at 10:15:05AM +0000, Joseph S. Myers wrote:
> This test really passes in the form given?  (I'd have expected failures 
> because of the "previous declaration" and "previous definition" warnings 
> it doesn't check for.)

Yes, my testcase was broken, sorry.

FreeBSD developer Bruce Evans mentioned to me that
a definition (i.e., a declaration with an initializer) following
a declaration (i.e., a tentative definition) can never be redundant.
Also, earlier on in the if statement, we already avoided warning
for externs, so only weird cases are left. :)

Based on this feedback, I want to change my patch as follows:

	* c-decl.c (diagnose_mismatched_decls):  With -Wredundant-decls,
	do not issue warning for a variable definition following
	a declaration.

Index: c-decl.c
RCS file: /cvsroot/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.630.6.16
diff -u -u -r1.630.6.16 c-decl.c
--- c-decl.c	16 Aug 2005 20:34:19 -0000	1.630.6.16
+++ c-decl.c	1 Sep 2005 02:46:51 -0000
@@ -1559,7 +1559,10 @@
       && !(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)))
+	   && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
+      /* Don't warn about a variable definition following a declaration.  */
+      && !(TREE_CODE (newdecl) == VAR_DECL
+	   && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)))
       warning ("%Jredundant redeclaration of %qD", newdecl, newdecl);
       warned = true;

Craig Rodrigues

Attachment: Wredundant-decls-2.c
Description: Text document

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