]> gcc.gnu.org Git - gcc.git/commitdiff
Add options -Wunused-variable, -Wunused-function, -Wunused-label,
authorAndrew Cagney <cagney@gcc.gnu.org>
Wed, 17 May 2000 08:15:29 +0000 (08:15 +0000)
committerAndrew Cagney <cagney@gcc.gnu.org>
Wed, 17 May 2000 08:15:29 +0000 (08:15 +0000)
-Wunused-parameter.  Retain existing -Wunused behavour.  Document.

From-SVN: r33953

20 files changed:
gcc/ChangeLog
gcc/c-decl.c
gcc/c-typeck.c
gcc/ch/ChangeLog
gcc/ch/decl.c
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/cp/typeck.c
gcc/f/ChangeLog
gcc/f/top.c
gcc/flags.h
gcc/function.c
gcc/gcc.1
gcc/invoke.texi
gcc/java/ChangeLog
gcc/java/decl.c
gcc/java/lang.c
gcc/stmt.c
gcc/toplev.c

index 17dd13d330a2b245fcb96015f4c5f2f34182f9cf..425ab785599450862db564cf8b6f6a097af2653c 100644 (file)
@@ -1,3 +1,34 @@
+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
index 301a32279778927459609a37338564b30b32d0be..040b695f889925ad7d5e67f0061d02bed8a2fa00 100644 (file)
@@ -754,7 +754,7 @@ c_decode_option (argc, argv)
       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;
@@ -1121,7 +1121,7 @@ poplevel (keep, reverse, functionbody)
              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;
 
@@ -1282,7 +1282,7 @@ pop_label_level ()
              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;
index 25c19e25784147e770e85a26bdbc7b446a93d115..0f01c578d4d0d06518257603f65a731b7f1dd6e2 100644 (file)
@@ -3531,7 +3531,7 @@ internal_build_compound_expr (list, first_p)
       /* 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");
@@ -3546,7 +3546,7 @@ internal_build_compound_expr (list, first_p)
      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);
index 45262b340e74f318ce5f58d26b24ed6b3f29c48f..a491bb376eb7f9aa057fc1c845d605fbec42fbee 100644 (file)
@@ -1,3 +1,9 @@
+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
index 9d5fd0dcfef641cb75047ccef13e2434cdc9b5b7..45f2656e567e4c044bb55b557874ec3040ab8000 100644 (file)
@@ -799,7 +799,7 @@ c_decode_option (argc, argv)
        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;
@@ -2973,7 +2973,7 @@ poplevel (keep, reverse, functionbody)
              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;
 
index 1400181faa193d91823cb39a7d713e5eaa92b0d4..d6b8431782d8bf9847dfdeefcb8507bceaccfa90 100644 (file)
@@ -1,3 +1,12 @@
+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.
index e32f2435612d20513b1fdf689eef5e492bbcc6b4..6f09a7aee73a9bfc45b28d9c4317d5c97a90189c 100644 (file)
@@ -1194,7 +1194,7 @@ pop_label (link)
          /* 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);
     }
 
index 39faa5d7e8d88ae7d4a4f23b3eb7e1696c21567b..fb399dbf6e8d0e1384aa78d6e3a8f2a751195061 100644 (file)
@@ -773,7 +773,7 @@ lang_decode_option (argc, argv)
       else if (!strcmp (p, "all"))
        {
          warn_return_type = setting;
-         warn_unused = setting;
+         set_Wunused (setting);
          warn_implicit = setting;
          warn_switch = setting;
          warn_format = setting;
index 671a66659ee5355a06f63bb3342039c41557813c..45c144530c59c769108cc8df0c58c09ed9b29edd 100644 (file)
@@ -5058,13 +5058,13 @@ build_x_compound_expr (list)
       /* 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
 
index c33a7904e3aa6db0bc53d7cf255469e1f46cc241..9eb3ccee06bb70827b4cd22b418cac16f507dc7a 100644 (file)
@@ -1,3 +1,8 @@
+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
index c48e9f1b7d4c510b7f1b9e7b9cc0c9eb0738e6c0..91db6d01803aa56f1ce7b1a1812c8fa0c3ab640a 100644 (file)
@@ -510,7 +510,7 @@ ffe_decode_option (argc, argv)
             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;
index 9ca120c202004ee1d97c2ff12c39ae4aa5e59dd3..3c543bc5bcd857d191b32e9135c222fddfdd14e2 100644 (file)
@@ -71,9 +71,17 @@ extern int inhibit_warnings;
 
 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.  */
 
index 9fd40cc237918afeca9f79db2cded9f673e2219a..0f6785b9bdc284f67e2b19157fc9a1496e97139c 100644 (file)
@@ -6492,7 +6492,11 @@ expand_function_end (filename, line, end_bindings)
     }
 
   /* 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;
 
index d9543fa6edc538101ca2004f1c8fded36301761a..e1907510e397c6e4c643b7f4fa61e1d2f1318dae 100644 (file)
--- a/gcc/gcc.1
+++ b/gcc/gcc.1
@@ -20,7 +20,7 @@
 .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)
@@ -206,6 +206,11 @@ in the following sections.
 \-Wtrigraphs
 \-Wuninitialized
 \-Wunused
+\-Wunused-function
+\-Wunused-label
+\-Wunused-parameter
+\-Wunused-variable
+\-Wunused-value
 \-Wwrite\-strings
 .TP
 .B Debugging Options
@@ -1694,10 +1699,50 @@ return-value in a function whose return-type is not \c
 .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
index c008ed037dfb80c9c74852bc69f3aa21fa470c71..4261cc6f22e426d79113e04e4c77222bc483880a 100644 (file)
@@ -132,7 +132,8 @@ in the following sections.
 -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
@@ -1538,19 +1539,41 @@ provoke warnings when this option is used.
 @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.
index 2f7aff924a0920ebc66bda0760f7e0bd387021e8..f30afabbb4d0060041b2055ee2b34cf031991b2b 100644 (file)
@@ -1,4 +1,10 @@
-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  &lt;tromey@cygnus.com&gt;
 
        * check_init.c (check_init): Constify local char *.
        * class.c (push_class): Constify local char *.
index 5757b2c8f32054d185fdb24894488de97171c8fc..a79bb9112529143cd3126d9c6ad070b831431ca0 100644 (file)
@@ -1387,7 +1387,7 @@ poplevel (keep, reverse, functionbody)
              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;
 
index 4bef553a95a67d1214022e945984731598366ebb..2a1d142ed3870d9e133d75832e7496af47303fe1 100644 (file)
@@ -258,7 +258,7 @@ lang_decode_option (argc, argv)
       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;
     }
 
index 0626e2c3e340e18e4c5c603e137b077cd2eb5723..a3b72ea3259652da179893419a1b14f80d271b1e 100644 (file)
@@ -1857,12 +1857,13 @@ expand_expr_stmt (exp)
      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);
     }
 
@@ -3575,7 +3576,7 @@ warn_about_unused_variables (vars)
 {
   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)
index bcb81f34bdf65d4c0e327dbddd1a0c9507376790..470a6ab6314c68275b66cfb891e0997b9ec081c5 100644 (file)
@@ -1289,9 +1289,30 @@ int extra_warnings = 0;
 
 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.  */
 
@@ -1354,7 +1375,11 @@ int warn_padded;
 
 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,
@@ -1905,7 +1930,7 @@ check_global_declarations (vec, len)
         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)
@@ -1926,9 +1951,10 @@ check_global_declarations (vec, len)
       /* 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)
@@ -3685,6 +3711,7 @@ display_help ()
                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");
@@ -3995,6 +4022,14 @@ decode_W_option (arg)
       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;
 
This page took 0.157715 seconds and 5 git commands to generate.