This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] -W -> -Wextra (was RFC: Named warnings)
- From: Phil Edwards <phil at jaj dot com>
- To: Zack Weinberg <zack at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 23 Jan 2003 23:27:17 -0500
- Subject: [PATCH] -W -> -Wextra (was RFC: Named warnings)
- References: <3E309188.1060508@apple.com> <8765sfqqvv.fsf@egil.codesourcery.com> <20030124040355.GA26693@disaster.jaj.com>
On Thu, Jan 23, 2003 at 11:03:55PM -0500, Phil Edwards wrote:
> On Thu, Jan 23, 2003 at 05:27:00PM -0800, Zack Weinberg wrote:
>
> > Oh, we should get Phil's -Wextra patch in first (or did it finally get
> > approved?)
>
> Never did. I'll post an updated version shortly.
Like so.
2003-01-23 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.
* 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.360
diff -u -3 -p -r1.360 c-decl.c
--- c-decl.c 18 Jan 2003 02:26:40 -0000 1.360
+++ c-decl.c 24 Jan 2003 04:12:46 -0000
@@ -4175,7 +4175,7 @@ grokdeclarator (declarator, declspecs, d
{
/* 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
@@ -6544,7 +6544,7 @@ c_expand_body (fndecl, nested_p, can_def
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.216
diff -u -3 -p -r1.216 c-typeck.c
--- c-typeck.c 9 Jan 2003 11:13:02 -0000 1.216
+++ c-typeck.c 24 Jan 2003 04:12:46 -0000
@@ -3570,7 +3570,7 @@ internal_build_compound_expr (list, firs
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.95
diff -u -3 -p -r1.95 flags.h
--- flags.h 23 Jan 2003 02:57:26 -0000 1.95
+++ flags.h 24 Jan 2003 04:13:25 -0000
@@ -86,7 +86,8 @@ extern int inhibit_warnings;
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.393
diff -u -3 -p -r1.393 function.c
--- function.c 16 Jan 2003 15:13:03 -0000 1.393
+++ function.c 24 Jan 2003 04:12:46 -0000
@@ -6795,9 +6795,10 @@ expand_function_end (filename, line, end
}
/* 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.286
diff -u -3 -p -r1.286 stmt.c
--- stmt.c 21 Jan 2003 20:52:44 -0000 1.286
+++ stmt.c 24 Jan 2003 04:12:46 -0000
@@ -2148,7 +2148,7 @@ expand_expr_stmt_value (exp, want_value,
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: toplev.c
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/gcc/toplev.c,v
retrieving revision 1.698
diff -u -3 -p -r1.698 toplev.c
--- toplev.c 23 Jan 2003 02:57:26 -0000 1.698
+++ toplev.c 24 Jan 2003 04:13:26 -0000
@@ -1411,7 +1411,7 @@ int inhibit_warnings = 0;
int warn_system_headers = 0;
-/* Print various extra warnings. -W. */
+/* Print various extra warnings. -W/-Wextra. */
int extra_warnings = 0;
@@ -1506,7 +1506,7 @@ int warn_deprecated_decl = 1;
int warn_strict_aliasing;
-/* Likewise for -W. */
+/* Like f_options, but for -W. */
static const lang_independent_options W_options[] =
{
@@ -1550,6 +1550,8 @@ static const lang_independent_options W_
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") },
{"strict-aliasing", &warn_strict_aliasing, 1,
@@ -3743,7 +3745,6 @@ display_help ()
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--;)
{
@@ -4116,6 +4117,14 @@ decode_W_option (arg)
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.226
diff -u -3 -p -r1.226 invoke.texi
--- doc/invoke.texi 23 Jan 2003 10:14:34 -0000 1.226
+++ doc/invoke.texi 24 Jan 2003 04:13:31 -0000
@@ -212,7 +212,7 @@ in the following sections.
@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
@@ -950,7 +950,7 @@ Print (on the standard output) a descrip
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.
@@ -2288,8 +2288,8 @@ To suppress this warning cast the expres
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
@@ -2402,9 +2402,12 @@ in some cases, and there is no simple wa
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
@@ -2431,7 +2434,7 @@ For example, an expression such as @samp
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
@@ -2459,17 +2462,6 @@ incorrect result when the signed value i
(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:
@@ -2478,6 +2470,47 @@ For example, the following code would ca
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
@@ -2678,8 +2711,8 @@ casts like @code{(unsigned) -1}.
@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