public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "yar at bsd dot chem dot msu dot ru" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/30006]  New: Compound literal in structure initializer causes irrelevant warning
Date: Tue, 28 Nov 2006 08:47:00 -0000	[thread overview]
Message-ID: <bug-30006-13638@http.gcc.gnu.org/bugzilla/> (raw)

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


             reply	other threads:[~2006-11-28  8:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-28  8:47 yar at bsd dot chem dot msu dot ru [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-30006-13638@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).