Article View: gnu.gcc.bug
Article #927GCC 2.2.2 does not warn about partly bracketed initializers
From: Paul Eggert
Date: Wed, 12 Aug 1992 01:42
Date: Wed, 12 Aug 1992 01:42
71 lines
2679 bytes
2679 bytes
GCC 2.2.2 (Sparc, SunOS 4.1.2) does not warn about partly bracketed
initializers. For example, in the following program, GCC does not
have an option to warn about the missing braces around `1,2':
struct s { int f, g; };
struct t { struct s h; int i; };
struct t x = { 1, 2, 3 };
This is a nice warning to have because it catches some common typographical
errors. This warning is also listed as a common warning in the ANSI C
standard (Appendix E). Here's a patch that generates this warning when the -W
option is used.
Wed Aug 12 01:23:10 1992 Paul Eggert (eggert@twinsun.com)
* c-typeck.c (process_init_constructor): Warn about partly
bracketed initializers.
===================================================================
RCS file: c-typeck.c,v
retrieving revision 2.2.2.4
diff -c -r2.2.2.4 c-typeck.c
*** c-typeck.c 1992/08/07 22:38:54 2.2.2.4
--- c-typeck.c 1992/08/12 01:23:10
***************
*** 4825,4831 ****
no matter how the data was given to us. */
if (elts)
! tail = *elts;
else
tail = CONSTRUCTOR_ELTS (init);
--- 4825,4835 ----
no matter how the data was given to us. */
if (elts)
! {
! if (extra_warnings)
! warning ("aggregate has a partly bracketed initializer");
! tail = *elts;
! }
else
tail = CONSTRUCTOR_ELTS (init);
===================================================================
RCS file: invoke.texi,v
retrieving revision 2.2.2.2
diff -c -r2.2.2.2 invoke.texi
*** invoke.texi 1992/08/07 22:38:54 2.2.2.2
--- invoke.texi 1992/08/12 01:23:10
***************
*** 623,628 ****
--- 623,639 ----
A storage-class specifier like @code{static} appears other than
at the beginning of a declaration. According to the C Standard,
this usage is obsolescent.
+
+ @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 @samp{x.h}:
+
+ @example
+ struct s @{ int f, g; @};
+ struct t @{ struct s h; int i; @};
+ struct t x = @{ 1, 2, 3 @};
+ @end example
@end itemize
@item -Wimplicit
Technical Details
Message-ID:
<9208120142.AA27113@farside.twinsun.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!usc!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggertShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!usc!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggert From: eggert@twinsun.COM (Paul Eggert) Newsgroups: gnu.gcc.bug Subject: GCC 2.2.2 does not warn about partly bracketed initializers Message-ID: <9208120142.AA27113@farside.twinsun.com> Date: 12 Aug 92 01:42:39 GMT Sender: gnulists@ai.mit.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 71 Approved: bug-gcc@prep.ai.mit.edu