public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/36839]  New: struct with only anonymous unions plus flexible array member
@ 2008-07-15 16:33 rtc at gmx dot de
  2008-12-27 20:33 ` [Bug c/36839] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: rtc at gmx dot de @ 2008-07-15 16:33 UTC (permalink / raw)
  To: gcc-bugs

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 <stdio.h>

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


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

end of thread, other threads:[~2014-04-15 20:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-36839-4@http.gcc.gnu.org/bugzilla/>
2014-04-15 20:22 ` [Bug c/36839] struct with only anonymous unions plus flexible array member mpolacek at gcc dot gnu.org
2008-07-15 16:33 [Bug c/36839] New: " rtc at gmx dot de
2008-12-27 20:33 ` [Bug c/36839] " pinskia at gcc dot gnu dot org
2008-12-27 20:46 ` pinskia at gcc dot gnu dot org
2009-02-27 20:28 ` vegard dot nossum at gmail dot com
2009-02-27 20:32 ` vegard dot nossum at gmail dot com
2009-02-27 20:58 ` joseph at codesourcery dot com

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).