From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25817 invoked by alias); 28 Nov 2006 08:47:35 -0000 Received: (qmail 25748 invoked by uid 48); 28 Nov 2006 08:47:25 -0000 Date: Tue, 28 Nov 2006 08:47:00 -0000 Subject: [Bug c/30006] New: Compound literal in structure initializer causes irrelevant warning X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "yar at bsd dot chem dot msu dot ru" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-11/txt/msg02397.txt.bz2 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