public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/30006]  New: Compound literal in structure initializer causes irrelevant warning
@ 2006-11-28  8:47 yar at bsd dot chem dot msu dot ru
  2006-12-02  8:10 ` [Bug c/30006] Compound literal in structure initializer causes missing initializer warning to happen pinskia at gcc dot gnu dot org
  2008-06-06  9:51 ` he at uninett dot no
  0 siblings, 2 replies; 4+ messages in thread
From: yar at bsd dot chem dot msu dot ru @ 2006-11-28  8:47 UTC (permalink / raw)
  To: gcc-bugs

Note: This report doesn't use the FreeBSD system GCC compiler; it uses an
original GCC 4.3.0 snapshot built and installed separately. However, the bug
also persists in GCC 3.4.6 found in FreeBSD, and in original GCC 4.2.0.

The complete test.c program:

struct foo {
        char *p;
        int i;
} bar = {
#ifdef BUG
        .p = (char[]){"abc"}
#else
        .p = "abc"
#endif
};

I.e., it will use a plain string to initialize bar.p if BUG is undefined,
but it will use a compound literal if BUG is defined.

The attempts to compile it (blank lines added for clarity):

$gcc43 -v
Using built-in specs.
Target: i386-portbld-freebsd7.0
Configured with: ./..//gcc-4.3-20061125/configure --disable-nls
--with-system-zlib --with-libiconv-prefix=/usr/local --with-gmp=/usr/local
--program-suffix=43 --libdir=/usr/local/lib/gcc-4.3.0
--with-gxx-include-dir=/usr/local/lib/gcc-4.3.0/include/c++/
--infodir=/usr/local/info/gcc43 --disable-rpath --prefix=/usr/local
i386-portbld-freebsd7.0
Thread model: posix
gcc version 4.3.0 20061125 (experimental)

$gcc43 -Wall -W -Werror -c test.c

$gcc43 -DBUG -Wall -W -Werror -c test.c
cc1: warnings being treated as errors
test.c:10: warning: missing initializer
test.c:10: warning: (near initialization for 'bar.i')

That is, using a compound literal instead of a plain string
to initialize bar.p leads to a warning on a different structure
member, bar.i.

AFAIK GCC would issue such a warning if an old-style structure
initializer were used and not all its members were specified.
However, the example program uses a C99 structure initializer,
and GCC is happy about it unless the compound literal is there
(see the successful compilation when BUG wasn't defined.)

Although it's just a warning, it can be painful for projects
that enforce -Werror policy for their code.

Thanks a lot!


-- 
           Summary: Compound literal in structure initializer causes
                    irrelevant warning
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: yar at bsd dot chem dot msu dot ru
 GCC build triplet: i386-portbld-freebsd7.0
  GCC host triplet: i386-portbld-freebsd7.0
GCC target triplet: i386-portbld-freebsd7.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30006


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-04-18 14:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-30006-4@http.gcc.gnu.org/bugzilla/>
2012-04-18 12:25 ` [Bug c/30006] Compound literal in structure initializer causes missing initializer warning to happen vadmium+gc at gmail dot com
2012-04-18 14:00 ` manu at gcc dot gnu.org
2006-11-28  8:47 [Bug c/30006] New: Compound literal in structure initializer causes irrelevant warning yar at bsd dot chem dot msu dot ru
2006-12-02  8:10 ` [Bug c/30006] Compound literal in structure initializer causes missing initializer warning to happen pinskia at gcc dot gnu dot org
2008-06-06  9:51 ` he at uninett dot no

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).