[PATCH] Recognize -Wextra, update manual (take 2).

Phil Edwards phil@jaj.com
Mon Jun 10 00:06:00 GMT 2002


(Zack, your texi2pod.pl patch fixed those warngings; the text shows up in
gcc.1 now.  It should be applied.)

This revision incorporates comments made by Joseph and Zack.  More are
welcome.  (I still can't think of a good example of ambiguous virtual bases,
and none of the testsuite tests are checking for that warning in particular.)


2002-06-10  Phil Edwards  <pme@gcc.gnu.org>

        Rename -W to -Wextra.
        * c-decl.c:  Update comments.
        * c-typeck.c:  Likewise.
        * flags.h:  Likewise.
        * function.c:  Likewise.
        * stmt.c:  Likewise.
        * real.c:  Add comment explaining why this is not an oversight.
        * toplev.c:  Update comments.
        (W_options):  Add 'extra'.
        (display_help):  Remove '-W'.
        (decode_W_option):  Special warn_uninitialized treatment in the case
        of -Wextra.
        * doc/invoke.texi:  Update with new entries.


Index: c-decl.c
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/gcc/c-decl.c,v
retrieving revision 1.332
diff -u -3 -r1.332 c-decl.c
--- c-decl.c	7 Jun 2002 22:20:11 -0000	1.332
+++ c-decl.c	9 Jun 2002 09:00:05 -0000
@@ -4522,7 +4522,7 @@
 	    {
 	      /* Type qualifiers on a function return type are normally
 		 permitted by the standard but have no effect, so give a
-		 warning at -W.  Qualifiers on a void return type have
+		 warning at -Wextra.  Qualifiers on a void return type have
 		 meaning as a GNU extension, and are banned on function
 		 definitions in ISO C.  FIXME: strictly we shouldn't
 		 pedwarn for qualified void return types except on function
@@ -6869,7 +6869,7 @@
   if (nested_p)
     ggc_pop_context ();
 
-  /* With just -W, complain only if function returns both with
+  /* With just -Wextra, complain only if function returns both with
      and without a value.  */
   if (extra_warnings
       && current_function_returns_value
Index: c-typeck.c
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/gcc/c-typeck.c,v
retrieving revision 1.195
diff -u -3 -r1.195 c-typeck.c
--- c-typeck.c	23 May 2002 15:47:58 -0000	1.195
+++ c-typeck.c	3 Jun 2002 07:01:49 -0000
@@ -3597,7 +3597,7 @@
   if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)))
     {
       /* The left-hand operand of a comma expression is like an expression
-         statement: with -W or -Wunused, we should warn if it doesn't have
+         statement: with -Wextra or -Wunused, we should warn if it doesn't have
 	 any side-effects, unless it was explicitly cast to (void).  */
       if ((extra_warnings || warn_unused_value)
            && ! (TREE_CODE (TREE_VALUE (list)) == CONVERT_EXPR
Index: flags.h
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/gcc/flags.h,v
retrieving revision 1.86
diff -u -3 -r1.86 flags.h
--- flags.h	25 May 2002 01:56:55 -0000	1.86
+++ flags.h	3 Jun 2002 07:02:31 -0000
@@ -86,7 +86,8 @@
 
 extern int warn_system_headers;
 
-/* Do print extra warnings (such as for uninitialized variables).  -W.  */
+/* Do print extra warnings (such as for uninitialized variables).
+   -W/-Wextra.  */
 
 extern int extra_warnings;
 
Index: function.c
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/gcc/function.c,v
retrieving revision 1.369
diff -u -3 -r1.369 function.c
--- function.c	4 Jun 2002 07:07:38 -0000	1.369
+++ function.c	10 Jun 2002 06:05:04 -0000
@@ -6864,9 +6864,10 @@
     }
 
   /* Warn about unused parms if extra warnings were specified.  */
-  /* Either ``-W -Wunused'' or ``-Wunused-parameter'' enables this
+  /* Either ``-Wextra -Wunused'' or ``-Wunused-parameter'' enables this
      warning.  WARN_UNUSED_PARAMETER is negative when set by
-     -Wunused.  */
+     -Wunused.  Note that -Wall implies -Wunused, so ``-Wall -Wextra'' will
+     also give these warnings.  */
   if (warn_unused_parameter > 0
       || (warn_unused_parameter < 0 && extra_warnings))
     {
Index: stmt.c
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/gcc/stmt.c,v
retrieving revision 1.266
diff -u -3 -r1.266 stmt.c
--- stmt.c	4 Jun 2002 07:07:56 -0000	1.266
+++ stmt.c	4 Jun 2002 09:00:12 -0000
@@ -2043,7 +2043,7 @@
   if (want_value == -1)
     want_value = expr_stmts_for_value != 0;
 
-  /* If -W, warn about statements with no side effects,
+  /* If -Wextra, warn about statements with no side effects,
      except for an explicit cast to void (e.g. for assert()), and
      except for last statement in ({...}) where they may be useful.  */
   if (! want_value
Index: real.c
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/gcc/real.c,v
retrieving revision 1.72
diff -u -3 -r1.72 real.c
--- real.c	28 May 2002 17:32:29 -0000	1.72
+++ real.c	3 Jun 2002 08:18:36 -0000
@@ -276,7 +276,7 @@
 #define CHARMASK 0x7f
 #endif
 
-extern int extra_warnings;
+extern int extra_warnings;  /* flags.h is not included  */
 extern const UEMUSHORT ezero[NE], ehalf[NE], eone[NE], etwo[NE];
 extern const UEMUSHORT elog2[NE], esqrt2[NE];
 
Index: toplev.c
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/gcc/toplev.c,v
retrieving revision 1.645
diff -u -3 -r1.645 toplev.c
--- toplev.c	6 Jun 2002 01:25:14 -0000	1.645
+++ toplev.c	10 Jun 2002 06:06:36 -0000
@@ -1390,7 +1390,7 @@
 
 int warn_system_headers = 0;
 
-/* Print various extra warnings.  -W.  */
+/* Print various extra warnings.  -W/-Wextra.  */
 
 int extra_warnings = 0;
 
@@ -1480,7 +1480,7 @@
 
 int warn_deprecated_decl = 1;
 
-/* Likewise for -W.  */
+/* Like f_options, but for -W.  */
 
 static const lang_independent_options W_options[] =
 {
@@ -1524,6 +1524,8 @@
    N_("Warn when an optimization pass is disabled") },
   {"deprecated-declarations", &warn_deprecated_decl, 1,
    N_("Warn about uses of __attribute__((deprecated)) declarations") },
+  {"extra", &extra_warnings, 1,
+   N_("Print extra (possibly unwanted) warnings") },
   {"missing-noreturn", &warn_missing_noreturn, 1,
    N_("Warn about functions which might be candidates for attribute noreturn") }
 };
@@ -3627,7 +3629,6 @@
   printf (_("  -pedantic               Issue warnings needed by strict compliance to ISO C\n"));
   printf (_("  -pedantic-errors        Like -pedantic except that errors are produced\n"));
   printf (_("  -w                      Suppress warnings\n"));
-  printf (_("  -W                      Enable extra warnings\n"));
 
   for (i = ARRAY_SIZE (W_options); i--;)
     {
@@ -4000,6 +4001,14 @@
   else if (!strcmp (arg, "no-unused"))
     {
       set_Wunused (0);
+    }
+  else if (!strcmp (arg, "extra"))
+    {
+      /* We save the value of warn_uninitialized, since if they put
+	 -Wuninitialized on the command line, we need to generate a
+	 warning about not using it without also specifying -O.  */
+      if (warn_uninitialized != 1)
+	warn_uninitialized = 2;
     }
   else
     return 0;
Index: doc/invoke.texi
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.149
diff -u -3 -r1.149 invoke.texi
--- doc/invoke.texi	1 Jun 2002 21:31:42 -0000	1.149
+++ doc/invoke.texi	10 Jun 2002 06:24:33 -0000
@@ -211,7 +211,7 @@
 @xref{Warning Options,,Options to Request or Suppress Warnings}.
 @gccoptlist{
 -fsyntax-only  -pedantic  -pedantic-errors @gol
--w  -W  -Wall  -Waggregate-return @gol
+-w  -Wextra  -Wall  -Waggregate-return @gol
 -Wcast-align  -Wcast-qual  -Wchar-subscripts  -Wcomment @gol
 -Wconversion  -Wno-deprecated-declarations @gol
 -Wdisabled-optimization  -Wno-div-by-zero  -Werror @gol
@@ -909,7 +909,7 @@
 understood by @command{gcc}.  If the @option{-v} option is also specified
 then @option{--help} will also be passed on to the various processes
 invoked by @command{gcc}, so that they can display the command line options
-they accept.  If the @option{-W} option is also specified then command
+they accept.  If the @option{-Wextra} option is also specified then command
 line options which have no documentation associated with them will also
 be displayed.
 
@@ -2104,8 +2104,8 @@
 All all the above @option{-Wunused} options combined.
 
 In order to get a warning about an unused function parameter, you must
-either specify @samp{-W -Wunused} or separately specify
-@option{-Wunused-parameter}.
+either specify @samp{-Wextra -Wunused} (note that @samp{-Wall} implies
+@samp{-Wunused}), or separately specify @option{-Wunused-parameter}.
 
 @item -Wuninitialized
 @opindex Wuninitialized
@@ -2215,9 +2215,12 @@
 the warning.
 
 @table @gcctabopt
-@item -W
+@item -Wextra
 @opindex W
-Print extra warning messages for these events:
+@opindex Wextra
+(This option used to be called @option{-W}.  The older name is still
+supported, but the newer name is more descriptive.)  Print extra warning
+messages for these events:
 
 @itemize @bullet
 @item
@@ -2244,7 +2247,7 @@
 but @samp{x[(void)i,j]} will not.
 
 @item
-An unsigned value is compared against zero with @samp{<} or @samp{<=}.
+An unsigned value is compared against zero with @samp{<} or @samp{>=}.
 
 @item
 A comparison like @samp{x<=y<=z} appears; this is equivalent to
@@ -2272,17 +2275,6 @@
 (But don't warn if @option{-Wno-sign-compare} is also specified.)
 
 @item
-An aggregate has a partly bracketed initializer.
-For example, the following code would evoke such a warning,
-because braces are missing around the initializer for @code{x.h}:
-
-@smallexample
-struct s @{ int f, g; @};
-struct t @{ struct s h; int i; @};
-struct t x = @{ 1, 2, 3 @};
-@end smallexample
-
-@item
 An aggregate has an initializer which does not initialize all members.
 For example, the following code would cause such a warning, because
 @code{x.h} would be implicitly initialized to zero:
@@ -2291,6 +2283,47 @@
 struct s @{ int f, g, h; @};
 struct s x = @{ 3, 4 @};
 @end smallexample
+
+@item
+A function parameter is declared without a type specifier in K&R-style
+functions:
+
+@smallexample
+void foo(bar) @{ @}
+@end smallexample
+
+@item
+An empty body occurs in an @samp{if} or @samp{else} statement.
+
+@item
+A pointer is compared against integer zero with @samp{<}, @samp{<=},
+@samp{>}, or @samp{>=}.
+
+@item
+A variable might be changed by @samp{longjmp} or @samp{vfork}.
+
+@item
+Any of several floating-point events that often indicate errors, such as
+overflow, underflow, loss of precision, etc.
+
+@item @r{(C++ only)}
+An enumerator and a non-enumerator both appear in a conditional expression.
+
+@item @r{(C++ only)}
+A non-static reference or non-static @samp{const} member appears in a
+class without constructors.
+
+@item @r{(C++ only)}
+Ambiguous virtual bases.
+
+@item @r{(C++ only)}
+Subscripting an array which has been declared @samp{register}.
+
+@item @r{(C++ only)}
+Taking the address of a variable which has been declared @samp{register}.
+
+@item @r{(C++ only)}
+A base class is not initialized in a derived class' copy constrcutor.
 @end itemize
 
 @item -Wno-div-by-zero
@@ -2482,8 +2515,8 @@
 @cindex signed and unsigned values, comparison warning
 Warn when a comparison between signed and unsigned values could produce
 an incorrect result when the signed value is converted to unsigned.
-This warning is also enabled by @option{-W}; to get the other warnings
-of @option{-W} without this warning, use @samp{-W -Wno-sign-compare}.
+This warning is also enabled by @option{-Wextra}; to get the other warnings
+of @option{-Wextra} without this warning, use @samp{-Wextra -Wno-sign-compare}.
 
 @item -Waggregate-return
 @opindex Waggregate-return



More information about the Gcc-patches mailing list