bug 1 $ cat bug.c
// Build as follows:
// gcc -W -Wall -O2 -std=gnu99 -c bug.c

#include <string.h>   

typedef signed char s8;
typedef signed short s16;
typedef signed int s32;
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;

struct ron{
        short ann;
        union{
                u16 ben;
                struct {
                        u8 bob;
                        u8 jon;
                };
        };
        u32 abe;
        u32 ada;
        char sue[];
};

int sid(char *buf){
        char *orig = buf;
        struct ron don = {
                .ann = 84,
                .ben = 76,
                .abe = 7,
                .ada = 8,
        };
        memcpy(buf,&don,sizeof don);
        buf += sizeof don;
        return buf - orig;
}
bug 0 $ gcc -W -Wall -O2 -std=gnu99 -c bug.c 
bug.c: In function ‘sid’:
bug.c:31: error: unknown field ‘ben’ specified in initializer
bug.c:31: warning: missing braces around initializer
bug.c:31: warning: (near initialization for ‘don.<anonymous>’)
bug 1 $ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic
--host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.1 20070123 (Red Hat 4.1.1-54)
bug 0 $


-- 
           Summary: C99 initializer can't see anon struct/union members
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: acahalan at gmail dot com


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

Reply via email to