From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20504 invoked by alias); 15 Jul 2008 16:33:07 -0000 Received: (qmail 20238 invoked by uid 48); 15 Jul 2008 16:32:24 -0000 Date: Tue, 15 Jul 2008 16:33:00 -0000 Subject: [Bug c/36839] New: struct with only anonymous unions plus flexible array member X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "rtc at gmx dot de" 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: 2008-07/txt/msg01314.txt.bz2 If I declare a struct with only anonymous unions plus a flexible array member, gcc 4.2.3 complains about "flexible array member in otherwise empty struct" Only if I add some other object to the struct the error goes away. removing the flexible array member causes the error to go away, and sizeof reports the expected size, which means that the struct is by no means "otherwise empty". Here is an example: cat > aufbug.c << EOF #include int main(void) { struct buggy { union { int a; char *b; }; #ifdef OTHER_MEMBER int x; #endif #ifdef FLEXIBLE char rest[]; #endif }; printf("%zu\n", sizeof (struct buggy)); return 0; } EOF $ rm -f aufbug && make aufbug CFLAGS="-g3 -Wall -O2 -DFLEXIBLE" && ./aufbug cc -g3 -Wall -O2 -DFLEXIBLE aufbug.c -o aufbug aufbug.c: In function 'main': aufbug.c:14: error: flexible array member in otherwise empty struct make: *** [aufbug] Error 1 $ rm -f aufbug && make aufbug CFLAGS="-g3 -Wall -O2 -DFLEXIBLE -DOTHER_MEMBER" && ./aufbug cc -g3 -Wall -O2 -DFLEXIBLE -DOTHER_MEMBER aufbug.c -o aufbug 8 $ rm -f aufbug && make aufbug CFLAGS="-g3 -Wall -O2" && ./aufbug cc -g3 -Wall -O2 aufbug.c -o aufbug 4 -- Summary: struct with only anonymous unions plus flexible array member Product: gcc Version: 4.2.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rtc at gmx dot de GCC build triplet: i486-pc-linux-gnu GCC host triplet: i486-pc-linux-gnu GCC target triplet: i486-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36839