Date: Sun, 16 Jan 2005 12:26:37 -0500 From: Chuck Swiger <cswiger@mac.com> To: Robert Watson <rwatson@FreeBSD.org> Cc: current@FreeBSD.org Subject: Re: gratuitous gcc warnings: unused function arguments? Message-ID: <41EAA3CD.1000903@mac.com> In-Reply-To: <Pine.NEB.3.96L.1050116120744.50371A-100000@fledge.watson.org> References: <Pine.NEB.3.96L.1050116120744.50371A-100000@fledge.watson.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Robert Watson wrote:
[ ...with regard to GCC errors like... ]
> cc -O -pipe -Wsystem-headers -Werror -Wall -Wno-format-y2k -W
> -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
> -Wno-uninitialized -c program.c
> program.c:48: warning: unused parameter 'argv'
> *** Error code 1
...and...
> cc -O -pipe -Wsystem-headers -Werror -Wall -Wno-format-y2k -W
> -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
> -Wno-uninitialized -c program.c
> program.c:49: warning: 'main' takes only zero or two arguments
> *** Error code 1
[ ... ]
> I'm not sure what is required to disable this warning, but I'd like to see
> us make it optional and not keyed to lower warning levels (such as 3).
Apparently, -Wunused-parameter is now being inferred from the combination of
-W and -Wall. The second error message is only generated when GCC thinks it
is compiling main() (or a moral equivalent thereof), so it doesn't seem likely
that that error would be generated for dummyfunction(int arg1, int arg2, char
*argv).
However, I'll try to offer a patch which does what you've asked for and let
someone else (hopefully a GCC expert/language pedant :-) second guess whether
the following is a good idea:
--- contrib/gcc/opts.c_orig Sun Jan 16 12:02:19 2005
+++ contrib/gcc/opts.c Sun Jan 16 12:15:23 2005
@@ -127,9 +127,6 @@
bool warn_unused_variable;
bool warn_unused_value;
-/* Hack for cooperation between set_Wunused and set_Wextra. */
-static bool maybe_warn_unused_parameter;
-
/* Type(s) of debugging information we are producing (if any). See
flags.h for the definitions of the different possible types of
debugging information. */
@@ -1559,7 +1556,6 @@
{
extra_warnings = setting;
warn_unused_value = setting;
- warn_unused_parameter = (setting && maybe_warn_unused_parameter);
/* We save the value of warn_uninitialized, since if they put
-Wuninitialized on the command line, we need to generate a
@@ -1576,13 +1572,7 @@
{
warn_unused_function = setting;
warn_unused_label = setting;
- /* Unused function parameter warnings are reported when either
- ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
- Thus, if -Wextra has already been seen, set warn_unused_parameter;
- otherwise set maybe_warn_extra_parameter, which will be picked up
- by set_Wextra. */
- maybe_warn_unused_parameter = setting;
- warn_unused_parameter = (setting && extra_warnings);
+ warn_unused_parameter = setting;
warn_unused_variable = setting;
warn_unused_value = setting;
}
--- contrib/gcc/c-decl.c_orig Sun Jan 16 11:39:32 2005
+++ contrib/gcc/c-decl.c Sun Jan 16 11:59:11 2005
@@ -5602,8 +5602,8 @@
/* It is intentional that this message does not mention the third
argument because it's only mentioned in an appendix of the
standard. */
- if (argct > 0 && (argct < 2 || argct > 3))
- pedwarn ("%J'%D' takes only zero or two arguments", decl1, decl1);
+ if (argct && (argct != 2))
+ warning ("%J'%D' takes only zero or two arguments", decl1, decl1);
if (! TREE_PUBLIC (decl1))
pedwarn ("%J'%D' is normally a non-static function", decl1, decl1);
[ This was made on 5.3-STABLE. ]
--
-Chuck
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?41EAA3CD.1000903>
