-Wunused-parameter. Retain existing -Wunused behavour. Document.
From-SVN: r33953
+Wed May 17 17:27:44 2000 Andrew Cagney <cagney@b1.cygnus.com>
+
+ * flags.h (warn_unused_function, warn_unused_label,
+ warn_unused_parameter, warn_unused_variable, warn_unused_value):
+ Replace ``warn_unused''.
+ (set_Wunused): Add declaration.
+ * toplev.c (set_Wunused): New function.
+ (warn_unused_function, warn_unused_label, warn_unused_parameter,
+ warn_unused_variable, warn_unused_value): New variables.
+ (W_options): Add -Wunused-function, -Wunused-function,
+ -Wunused-label, -Wunused-parameter, -Wunused-variable and
+ -Wunused-value. Delete -Wunused. Handled in decode_W_option.
+
+ * toplev.c (decode_W_option): Update -Wunused flags by calling
+ set_Wunused.
+ * c-decl.c (c_decode_option): Ditto for -Wall.
+
+ * stmt.c (expand_expr_stmt, expand_expr_stmt,
+ warn_about_unused_variables): Replace warn_unused with more
+ explicit warn_unused_value et.al.
+ * function.c (expand_function_end): Ditto.
+ * c-typeck.c (internal_build_compound_expr,
+ internal_build_compound_expr): Ditto.
+ * c-decl.c (poplevel, pop_label_level): Ditto.
+ * toplev.c (check_global_declarations): Replace warn_unused with
+ check for either warn_unused_function or warn_unused_variable.
+
+ * gcc.1, invoke.texi (Warning Options): Document
+ -Wunused-function, -Wunused-function, -Wunused-label,
+ -Wunused-parameter, -Wunused-variable and -Wunused-value options.
+
2000-05-16 Richard Henderson <rth@cygnus.com>
* config/ia64/crtbegin.asm (__dso_handle): Mark hidden if the
warn_implicit_int = 1;
mesg_implicit_function_declaration = 1;
warn_return_type = 1;
- warn_unused = 1;
+ set_Wunused (1);
warn_switch = 1;
warn_format = 1;
warn_char_subscripts = 1;
define_label (input_filename, lineno,
DECL_NAME (label));
}
- else if (warn_unused && !TREE_USED (label))
+ else if (warn_unused_label && !TREE_USED (label))
warning_with_decl (label, "label `%s' defined but not used");
IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
define_label (input_filename, lineno,
DECL_NAME (TREE_VALUE (link)));
}
- else if (warn_unused && !TREE_USED (TREE_VALUE (link)))
+ else if (warn_unused_label && !TREE_USED (TREE_VALUE (link)))
warning_with_decl (TREE_VALUE (link),
"label `%s' defined but not used");
IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0;
/* 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
any side-effects, unless it was explicitly cast to (void). */
- if ((extra_warnings || warn_unused)
+ if ((extra_warnings || warn_unused_value)
&& ! (TREE_CODE (TREE_VALUE (list)) == CONVERT_EXPR
&& TREE_TYPE (TREE_VALUE (list)) == void_type_node))
warning ("left-hand operand of comma expression has no effect");
side-effects, but computes a value which is not used. For example, in
`foo() + bar(), baz()' the result of the `+' operator is not used,
so we should issue a warning. */
- else if (warn_unused)
+ else if (warn_unused_value)
warn_if_unused_value (TREE_VALUE (list));
return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest);
+Wed May 17 17:27:44 2000 Andrew Cagney <cagney@b1.cygnus.com>
+
+ * decl.c (c_decode_option): Update -Wall unused flags by
+ calling set_Wunused.
+ (poplevel): Replace warn_unused with warn_unused_label.
+
2000-05-09 Zack Weinberg <zack@wolery.cumb.org>
* ch-tree.h: Update prototypes. Remove prototypes for
warn_uninitialized = 2;
warn_implicit = 1;
warn_return_type = 1;
- warn_unused = 1;
+ set_Wunused (1);
warn_char_subscripts = 1;
warn_parentheses = 1;
warn_missing_braces = 1;
define_label (input_filename, lineno,
DECL_NAME (label));
}
- else if (warn_unused && !TREE_USED (label))
+ else if (warn_unused_label && !TREE_USED (label))
warning_with_decl (label, "label `%s' defined but not used");
IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
+Wed May 17 17:27:44 2000 Andrew Cagney <cagney@b1.cygnus.com>
+
+ * decl.c (pop_label): Replace warn_unused with warn_unused_label.
+ * typeck.c (build_x_compound_expr): Replace warn_unused with
+ warn_unused_value.
+
+ * decl2.c (lang_decode_option): Update -Wall unused flags by
+ calling set_Wunused.
+
2000-05-16 Mark Mitchell <mark@codesourcery.com>
* cp-treeh (BINFO_NEW_VTABLE_MARKED): Update documentation.
/* Avoid crashing later. */
define_label (input_filename, 1, DECL_NAME (label));
}
- else if (warn_unused && !TREE_USED (label))
+ else if (warn_unused_label && !TREE_USED (label))
cp_warning_at ("label `%D' defined but not used", label);
}
else if (!strcmp (p, "all"))
{
warn_return_type = setting;
- warn_unused = setting;
+ set_Wunused (setting);
warn_implicit = setting;
warn_switch = setting;
warn_format = setting;
/* the left-hand operand of a comma expression is like an expression
statement: we should warn if it doesn't have any side-effects,
unless it was explicitly cast to (void). */
- if ((extra_warnings || warn_unused)
+ if ((extra_warnings || warn_unused_value)
&& !(TREE_CODE (TREE_VALUE(list)) == CONVERT_EXPR
&& TREE_TYPE (TREE_VALUE(list)) == void_type_node))
warning("left-hand operand of comma expression has no effect");
}
#if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
- else if (warn_unused)
+ else if (warn_unused_value)
warn_if_unused_value (TREE_VALUE(list));
#endif
+Wed May 17 17:27:44 2000 Andrew Cagney <cagney@b1.cygnus.com>
+
+ * top.c (ffe_decode_option): Update -Wall unused flags by calling
+ set_Wunused.
+
2000-05-09 Zack Weinberg <zack@wolery.cumb.org>
* com.c (ffecom_subscript_check_): Constify array_name
warning about not using it without also specifying -O. */
if (warn_uninitialized != 1)
warn_uninitialized = 2;
- warn_unused = 1;
+ set_Wunused (1);
}
else
return 0;
extern int extra_warnings;
-/* Nonzero to warn about unused local variables. */
+/* Nonzero to warn about unused variables, functions et.al. Use
+ set_Wunused() to update the -Wunused-* flags that correspond to the
+ -Wunused option. */
-extern int warn_unused;
+extern void set_Wunused PARAMS ((int setting));
+
+extern int warn_unused_function;
+extern int warn_unused_label;
+extern int warn_unused_parameter;
+extern int warn_unused_variable;
+extern int warn_unused_value;
/* Nonzero to warn about code which is never reached. */
}
/* Warn about unused parms if extra warnings were specified. */
- if (warn_unused && extra_warnings)
+ /* Either ``-W -Wunused'' or ``-Wunused-parameter'' enables this
+ warning. WARN_UNUSED_PARAMETER is negative when set by
+ -Wunused. */
+ if (warn_unused_parameter > 0
+ || (warn_unused_parameter < 0 && extra_warnings))
{
tree decl;
.if n .sp
.if t .sp 0.4
..
-.Id $Id: gcc.1,v 1.13 1999/11/02 10:23:46 law Exp $
+.Id $Id: gcc.1,v 1.14 2000/04/11 06:01:52 loewis Exp $
.TH GCC 1 "\*(Dt" "GNU Tools" "GNU Tools"
.SH NAME
gcc, g++ \- GNU project C and C++ Compiler (gcc-2.96)
\-Wtrigraphs
\-Wuninitialized
\-Wunused
+\-Wunused-function
+\-Wunused-label
+\-Wunused-parameter
+\-Wunused-variable
+\-Wunused-value
\-Wwrite\-strings
.TP
.B Debugging Options
.B void\c
\&.
.TP
+.B \-Wunused\-function
+Warn whenever a static function is declared but not defined or a
+non\-inline static function is unused.
+.TP
+.B \-Wunused\-label
+Warn whenever a label is declared but not used.
+
+To suppress this warning use the
+.B unused
+attribute.
+.TP
+.B \-Wunused\-parameter
+Warn whenever a function parameter is unused aside from its declaration.
+
+To suppress this warning use the
+.B unused
+attribute.
+.TP
+.B \-Wunused\-variable
+Warn whenever a local variable or non\-constant static variable
+is unused aside from its declaration
+
+To suppress this warning use the
+.B unused
+attribute.
+.TP
+.B \-Wunused\-value
+Warn whenever a statement computes a result that is explicitly not used.
+
+To suppress this warning cast the expression to
+.B void\c
+\&.
+.TP
.B \-Wunused
-Warn whenever a local variable is unused aside from its declaration,
-whenever a function is declared static but never defined, and whenever
-a statement computes a result that is explicitly not used.
+All all the above `\|\c
+.B \-Wunused\c
+\&\|' options combined.
+
+In order to get a warning about an unused function parameter, you must
+either specify `\|\c
+.B \-W \-Wunused\c
+\&\|' or separatly specify `\|\c
+.B \-Wunused\-parameter\c
+\&\|'.
.TP
.B \-Wswitch
Warn whenever a \c
-Wparentheses -Wpointer-arith -Wredundant-decls
-Wreturn-type -Wshadow -Wsign-compare -Wswitch
-Wtrigraphs -Wundef -Wuninitialized -Wunknown-pragmas -Wunreachable-code
--Wunused -Wwrite-strings
+-Wunused -Wunused-function -Wunused-label -Wunused-parameter
+-Wunused-variable -Wunused-value -Wwrite-strings
@end smallexample
@item C-only Warning Options
@item -Wtrigraphs
Warn if any trigraphs are encountered (assuming they are enabled).
-@item -Wunused
-Warn whenever a variable is unused aside from its declaration,
-whenever a function is declared static but never defined, whenever a
-label is declared but not used, and whenever a statement computes a
-result that is explicitly not used.
+@item -Wunused-function
+Warn whenever a static function is declared but not defined or a
+non\-inline static function is unused.
-In order to get a warning about an unused function parameter, you must
-specify both @samp{-W} and @samp{-Wunused}.
+@item -Wunused-label
+Warn whenever a label is declared but not used.
+
+To suppress this warning use the @samp{unused} attribute
+(@pxref{Variable Attributes}).
+
+@item -Wunused-parameter
+Warn whenever a function parameter is unused aside from its declaration.
+
+To suppress this warning use the @samp{unused} attribute
+(@pxref{Variable Attributes}).
-To suppress this warning for an expression, simply cast it to void. For
-unused variables, parameters and labels, use the @samp{unused} attribute
+@item -Wunused-variable
+Warn whenever a local variable or non-constant static variable is unused
+aside from its declaration
+
+To suppress this warning use the @samp{unused} attribute
(@pxref{Variable Attributes}).
+@item -Wunused-value
+Warn whenever a statement computes a result that is explicitly not used.
+
+To suppress this warning cast the expression to @samp{void}.
+
+@item -Wunused
+All all the above @samp{-Wunused} options combined.
+
+In order to get a warning about an unused function parameter, you must
+either specify @samp{-W -Wunused} or separatly specify
+@samp{-Wunused-parameter}.
+
@item -Wuninitialized
Warn if an automatic variable is used without first being initialized or
if a variable may be clobbered by a @code{setjmp} call.
-2000-05-09 Zack Weinberg <zack@wolery.cumb.org>
+Wed May 17 17:27:44 2000 Andrew Cagney <cagney@b1.cygnus.com>
+
+ * lang.c (lang_decode_option): Update -Wunused flags by calling
+ set_Wunused.
+ * decl.c (poplevel): Replace warn_unused with warn_unused_label.
+
+2000-04-19 Tom Tromey <tromey@cygnus.com>
* check_init.c (check_init): Constify local char *.
* class.c (push_class): Constify local char *.
define_label (input_filename, lineno,
DECL_NAME (label));
}
- else if (warn_unused && !TREE_USED (label))
+ else if (warn_unused[UNUSED_LABEL] && !TREE_USED (label))
warning_with_decl (label, "label `%s' defined but not used");
IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
flag_redundant = 1;
/* When -Wall given, enable -Wunused. We do this because the C
compiler does it, and people expect it. */
- warn_unused = 1;
+ set_Wunused (1);
return 1;
}
except inside a ({...}) where they may be useful. */
if (expr_stmts_for_value == 0 && exp != error_mark_node)
{
- if (! TREE_SIDE_EFFECTS (exp) && (extra_warnings || warn_unused)
+ if (! TREE_SIDE_EFFECTS (exp)
+ && (extra_warnings || warn_unused_value)
&& !(TREE_CODE (exp) == CONVERT_EXPR
&& TREE_TYPE (exp) == void_type_node))
warning_with_file_and_line (emit_filename, emit_lineno,
"statement with no effect");
- else if (warn_unused)
+ else if (warn_unused_value)
warn_if_unused_value (exp);
}
{
tree decl;
- if (warn_unused)
+ if (warn_unused_variable)
for (decl = vars; decl; decl = TREE_CHAIN (decl))
if (TREE_CODE (decl) == VAR_DECL
&& ! TREE_USED (decl)
int warnings_are_errors = 0;
-/* Nonzero to warn about unused local variables. */
+/* Nonzero to warn about unused variables, functions et.al. */
-int warn_unused;
+int warn_unused_function;
+int warn_unused_label;
+int warn_unused_parameter;
+int warn_unused_variable;
+int warn_unused_value;
+
+void
+set_Wunused (setting)
+ int setting;
+{
+ warn_unused_function = setting;
+ warn_unused_label = setting;
+ /* Unused function parameter warnings are reported when either ``-W
+ -Wunused'' or ``-Wunused-parameter'' is specified. Differentiate
+ -Wunused by setting WARN_UNUSED_PARAMETER to -1 */
+ if (!setting)
+ warn_unused_parameter = 0;
+ else if (!warn_unused_parameter)
+ warn_unused_parameter = -1;
+ warn_unused_variable = setting;
+ warn_unused_value = setting;
+}
/* Nonzero to warn about code which is never reached. */
lang_independent_options W_options[] =
{
- {"unused", &warn_unused, 1, "Warn when a variable is unused" },
+ {"unused-function", &warn_unused_function, 1, "Warn when a function is unused" },
+ {"unused-label", &warn_unused_label, 1, "Warn when a label is unused" },
+ {"unused-parameter", &warn_unused_parameter, 1, "Warn when a function parameter is unused" },
+ {"unused-variable", &warn_unused_variable, 1, "Warn when a variable is unused" },
+ {"unused-value", &warn_unused_value, 1, "Warn when an expression value is unused" },
{"error", &warnings_are_errors, 1, ""},
{"shadow", &warn_shadow, 1, "Warn when one local variable shadows another" },
{"switch", &warn_switch, 1,
because many programs have static variables
that exist only to get some text into the object file. */
if (TREE_CODE (decl) == FUNCTION_DECL
- && (warn_unused
+ && (warn_unused_function
|| TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
&& DECL_INITIAL (decl) == 0
&& DECL_EXTERNAL (decl)
/* Warn about static fns or vars defined but not used,
but not about inline functions or static consts
since defining those in header files is normal practice. */
- if (warn_unused
- && ((TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
- || (TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
+ if (((warn_unused_function
+ && TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
+ || (warn_unused_variable
+ && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
&& ! DECL_IN_SYSTEM_HEADER (decl)
&& ! DECL_EXTERNAL (decl)
&& ! TREE_PUBLIC (decl)
W_options[i].string, description);
}
+ printf (" -Wunused Enable unused warnings\n");
printf (" -Wid-clash-<num> Warn if 2 identifiers have the same first <num> chars\n");
printf (" -Wlarger-than-<number> Warn if an object is larger than <number> bytes\n");
printf (" -p Enable function profiling\n");
if (larger_than_size != -1)
warn_larger_than = 1;
}
+ else if (!strcmp (arg, "unused"))
+ {
+ set_Wunused (1);
+ }
+ else if (!strcmp (arg, "no-unused"))
+ {
+ set_Wunused (0);
+ }
else
return 0;