This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: static followed by non-static fails to give a warning.
- To: ghost at aladdin dot com
- Subject: Re: static followed by non-static fails to give a warning.
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Sat, 16 Jan 1999 20:42:09 -0500 (EST)
- Cc: egcs-bugs at cygnus dot com
> From: "L. Peter Deutsch" <ghost@aladdin.com>
>
> I've now researched this question more fully myself.
>
> Unfortunately, a careful reading of sections 3.1.2.2 and 3.5 of the ANSI C
> standard has led me to conclude that gcc is, in fact, doing what the
> standard calls for. I don't like this, since a significant number of other
> compilers disagree, but it does seem to be the case.
Agreed. SunOS4 cc is the one I regularly run into which has
this problem.
> I would still very much like to see a warning for this, as an aid to
> portability, and I agree that -Wtraditional is a good way to activate it.
> Thanks for following up.
> --
> L. Peter Deutsch | Aladdin Enterprises :::: ghost@aladdin.com
You're welcome. FYI, I just checked the following patch into
the CVS repository for egcs. You should see this feature when
egcs-1.2 is released.
--Kaveh
Index: ChangeLog
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/ChangeLog,v
retrieving revision 1.2781
diff -u -p -r1.2781 ChangeLog
--- ChangeLog 1999/01/16 14:20:18 1.2781
+++ ChangeLog 1999/01/17 00:39:24
@@ -1,3 +1,11 @@
+Sat Jan 16 19:31:07 1999 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ * c-decl.c (duplicate_decls): If `warn_traditional', warn when
+ a non-static function declaration follows a static one.
+
+ * invoke.texi (-Wtraditional): Document the extra check now done
+ by this flag.
+
Sat Jan 16 15:13:46 1999 Jeffrey A Law (law@cygnus.com)
* pa.md (shadd): Create shadd insns, even if the result of the shift is
Index: c-decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-decl.c,v
retrieving revision 1.56
diff -u -p -r1.56 c-decl.c
--- c-decl.c 1998/12/16 20:53:39 1.56
+++ c-decl.c 1999/01/17 00:39:54
@@ -1,5 +1,5 @@
/* Process declarations and variables for C compiler.
- Copyright (C) 1988, 92-97, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1988, 92-98, 1999 Free Software Foundation, Inc.
This file is part of GNU CC.
@@ -1857,6 +1857,14 @@ duplicate_decls (newdecl, olddecl, diffe
&& TREE_PUBLIC (olddecl)
&& !TREE_PUBLIC (newdecl))
warning_with_decl (newdecl, "static declaration for `%s' follows non-static");
+
+ /* If warn_traditional, warn when a non-static function
+ declaration follows a static one. */
+ if (warn_traditional
+ && TREE_CODE (olddecl) == FUNCTION_DECL
+ && !TREE_PUBLIC (olddecl)
+ && TREE_PUBLIC (newdecl))
+ warning_with_decl (newdecl, "non-static declaration for `%s' follows static");
/* Warn when const declaration follows a non-const
declaration, but not for functions. */
Index: invoke.texi
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/invoke.texi,v
retrieving revision 1.86
diff -u -p -r1.86 invoke.texi
--- invoke.texi 1999/01/15 19:13:37 1.86
+++ invoke.texi 1999/01/17 00:40:08
@@ -1,4 +1,4 @@
-@c Copyright (C) 1988,89,92,93,94,95,96,97,98,1999 Free Software Foundation, Inc.
+@c Copyright (C) 1988, 89, 92-98, 1999 Free Software Foundation, Inc.
@c This is part of the GCC manual.
@c For copying conditions, see the file gcc.texi.
@@ -1548,6 +1548,10 @@ the block.
@item
A @code{switch} statement has an operand of type @code{long}.
+
+@item
+A non-@code{static} function declaration follows a @code{static} one.
+This construct is not accepted by some traditional C compilers.
@end itemize
@item -Wundef