Subject: -W{no-,}missing-init
To: None <tech-toolchain@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-toolchain
Date: 03/19/2007 01:47:12
Okay, here is a first cut of patches for -Wmissing-init (and
-Wno-missing-init).  These are relative to the 3.1 distribution source;
is that close enough to -current to be of use, or do I need to try to
convince -current to work for me?

The code changes seem to DTRT for me, at least.  I'm less sure of the
doc changes.

--- gnu/dist/gcc/gcc/c-common.c.OLD	Mon Mar 19 01:49:33 2007
+++ gnu/dist/gcc/gcc/c-common.c	Mon Mar 19 01:49:32 2007
@@ -278,6 +278,11 @@
 
 int warn_sign_compare;
 
+/* Warn about missing initializers.
+   -1 -> not specified (let -W control), 0 -> don't warn, 1 -> warn. */
+
+int warn_missing_init;
+
 /* Nonzero means warn about usage of long long when `-pedantic'.  */
 
 int warn_long_long = 1;
--- gnu/dist/gcc/gcc/c-common.h.OLD	Mon Mar 19 01:49:35 2007
+++ gnu/dist/gcc/gcc/c-common.h	Mon Mar 19 01:49:35 2007
@@ -446,6 +446,11 @@
 
 extern int warn_sign_compare;
 
+/* Warn about missing initializers.
+   -1 -> not specified (let -W control), 0 -> don't warn, 1 -> warn. */
+
+extern int warn_missing_init;
+
 /* Nonzero means warn about usage of long long when `-pedantic'.  */
 
 extern int warn_long_long;
--- gnu/dist/gcc/gcc/c-opts.c.OLD	Mon Mar 19 01:49:37 2007
+++ gnu/dist/gcc/gcc/c-opts.c	Mon Mar 19 01:49:37 2007
@@ -157,6 +157,7 @@
   OPT("Wmissing-braces",	CL_ALL,   OPT_Wmissing_braces)		     \
   OPT("Wmissing-declarations",	CL_C,     OPT_Wmissing_declarations)	     \
   OPT("Wmissing-format-attribute",CL_ALL, OPT_Wmissing_format_attribute)     \
+  OPT("Wmissing-init",		CL_ALL,   OPT_Wmissing_init)		     \
   OPT("Wmissing-prototypes",	CL_ALL,   OPT_Wmissing_prototypes)	     \
   OPT("Wmultichar",		CL_ALL,   OPT_Wmultichar)		     \
   OPT("Wnested-externs",	CL_C,     OPT_Wnested_externs)		     \
@@ -517,6 +518,7 @@
   warn_pointer_arith = (lang == clk_cplusplus);
   if (lang == clk_c)
     warn_sign_compare = -1;
+  warn_missing_init = -1;
 }
 
 /* Handle one command-line option in (argc, argv).
@@ -926,6 +928,10 @@
 
     case OPT_Wsign_compare:
       warn_sign_compare = on;
+      break;
+
+    case OPT_Wmissing_init:
+      warn_missing_init = on;
       break;
 
     case OPT_Wsign_promo:
--- gnu/dist/gcc/gcc/c-typeck.c.OLD	Mon Mar 19 01:49:40 2007
+++ gnu/dist/gcc/gcc/c-typeck.c	Mon Mar 19 01:49:39 2007
@@ -5532,8 +5532,10 @@
 	abort ();
     }
 
-  /* Warn when some struct elements are implicitly initialized to zero.  */
-  if (extra_warnings
+  /* Warn when some struct elements are implicitly initialized to zero,
+    if -W but no -Wno-missing-init, or if -Wmissing-init. */
+  if (((extra_warnings && (warn_missing_init != 0))
+       || (warn_missing_init == 1))
       && constructor_type
       && TREE_CODE (constructor_type) == RECORD_TYPE
       && constructor_unfilled_fields)
--- gnu/dist/gcc/gcc/doc/gcc.1.OLD	Mon Mar 19 01:49:46 2007
+++ gnu/dist/gcc/gcc/doc/gcc.1	Mon Mar 19 01:49:44 2007
@@ -253,7 +253,7 @@
 \&\-Wimport  \-Winline  \-Wno-endif-labels 
 \&\-Wlarger-than-\fR\fIlen\fR  \fB\-Wlong-long 
 \&\-Wmain  \-Wmissing-braces 
-\&\-Wmissing-format-attribute  \-Wmissing-noreturn 
+\&\-Wmissing-format-attribute  \-Wmissing-init  \-Wmissing-noreturn 
 \&\-Wno-multichar  \-Wno-format-extra-args  \-Wno-format-y2k 
 \&\-Wno-import  \-Wnonnull  \-Wpacked  \-Wpadded 
 \&\-Wparentheses  \-Wpointer-arith  \-Wredundant-decls 
@@ -2179,6 +2179,7 @@
 .Ve
 .Ip "\(bu" 4
 An aggregate has an initializer which does not initialize all members.
+(But don't warn if \fB\-Wno-missing-init\fR is also specified.)
 For example, the following code would cause such a warning, because
 \&\f(CW\*(C`x.h\*(C'\fR would be implicitly initialized to zero:
 .Sp
@@ -2356,6 +2357,10 @@
 an incorrect result when the signed value is converted to unsigned.
 This warning is enabled by \fB\-W\fR, and by \fB\-Wall\fR
 in \*(C+ only.
+.Ip "\fB\-Wmissing-init\fR" 4
+.IX Item "-Wmissing-init"
+Warn when an aggregate initializer does not initialize all members.
+This warning is also enabled by \fB\-W\fR.
 .Ip "\fB\-Waggregate-return\fR" 4
 .IX Item "-Waggregate-return"
 Warn if any functions that return structures or unions are defined or
--- gnu/dist/gcc/gcc/doc/gcc.info.OLD	Mon Mar 19 01:49:56 2007
+++ gnu/dist/gcc/gcc/doc/gcc.info	Mon Mar 19 01:49:53 2007
@@ -431,7 +431,7 @@
           -Wimport  -Winline  -Wno-endif-labels 
           -Wlarger-than-LEN  -Wlong-long 
           -Wmain  -Wmissing-braces 
-          -Wmissing-format-attribute  -Wmissing-noreturn 
+          -Wmissing-format-attribute  -Wmissing-init  -Wmissing-noreturn 
           -Wno-multichar  -Wno-format-extra-args  -Wno-format-y2k 
           -Wno-import  -Wnonnull  -Wpacked  -Wpadded 
           -Wparentheses  -Wpointer-arith  -Wredundant-decls 
@@ -2400,8 +2400,9 @@
                struct t x = { 1, 2, 3 };
 
         * An aggregate has an initializer which does not initialize all
-          members.  For example, the following code would cause such a
-          warning, because `x.h' would be implicitly initialized to
+          members.  (But don't warn if `-Wno-missing-init' is also
+          specified.)  For example, the following code would cause such
+          a warning, because `x.h' would be implicitly initialized to
           zero:
 
                struct s { int f, g, h; };
@@ -2580,6 +2581,10 @@
      unsigned.  This warning is enabled by `-W', and by `-Wall' in C++
      only.
 
+`-Wmissing-init'
+     Warn when an aggregate initializer does not initialize all elements.
+     This warning is also enabled by `-W'.
+
 `-Waggregate-return'
      Warn if any functions that return structures or unions are defined
      or called.  (In languages where you can return an array, this also
@@ -23941,6 +23946,7 @@
 * Wmissing-braces:                       Warning Options.
 * Wmissing-declarations:                 Warning Options.
 * Wmissing-format-attribute:             Warning Options.
+* Wmissing-init:                         Warning Options.
 * Wmissing-noreturn:                     Warning Options.
 * Wmissing-prototypes:                   Warning Options.
 * Wmultichar:                            Warning Options.
--- gnu/dist/gcc/gcc/doc/invoke.texi.OLD	Mon Mar 19 01:50:04 2007
+++ gnu/dist/gcc/gcc/doc/invoke.texi	Mon Mar 19 01:50:01 2007
@@ -216,7 +216,7 @@
 -Wimport  -Winline  -Wno-endif-labels @gol
 -Wlarger-than-@var{len}  -Wlong-long @gol
 -Wmain  -Wmissing-braces @gol
--Wmissing-format-attribute  -Wmissing-noreturn @gol
+-Wmissing-format-attribute  -Wmissing-init  -Wmissing-noreturn @gol
 -Wno-multichar  -Wno-format-extra-args  -Wno-format-y2k @gol
 -Wno-import  -Wnonnull  -Wpacked  -Wpadded @gol
 -Wparentheses  -Wpointer-arith  -Wredundant-decls @gol
@@ -2427,6 +2427,7 @@
 
 @item
 An aggregate has an initializer which does not initialize all members.
+(But don't warn if @option{-Wno-missing-init} is also specified.)
 For example, the following code would cause such a warning, because
 @code{x.h} would be implicitly initialized to zero:
 
@@ -2636,6 +2637,14 @@
 an incorrect result when the signed value is converted to unsigned.
 This warning is enabled by @option{-W}, and by @option{-Wall}
 in C++ only.
+
+@item -Wmissing-init
+@opindex Wmissing-init
+@cindex warning for incomplete initializer
+@cindex incomplete initializer, warning
+@cindex initializer, incomplete warning
+Warn when an aggregate initializer does not initialize all elements.
+This warning is enabled by @option{-W}.
 
 @item -Waggregate-return
 @opindex Waggregate-return

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B