Re: gratuitous gcc warnings: unused function arguments?

From: Chuck Swiger <cswiger_at_mac.com>
Date: Sun, 16 Jan 2005 12:26:37 -0500
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
_at__at_ -127,9 +127,6 _at__at_
  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.  */
_at__at_ -1559,7 +1556,6 _at__at_
  {
    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
_at__at_ -1576,13 +1572,7 _at__at_
  {
    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
_at__at_ -5602,8 +5602,8 _at__at_
        /* 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
Received on Sun Jan 16 2005 - 16:24:45 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:26 UTC