[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

g++ 3.3 mixes up types when an initialized field in a union is not the first one



>Submitter-Id:	net
>Originator:	Andreas Oberritter
>Organization:	
>Confidential:	no
>Synopsis:	g++ 3.3 mixes up types when an initialized field in a union
is not the first one
>Severity:	serious
>Priority:	medium
>Category:	c++
>Class:		rejects-legal
>Release:	3.3 20030415 (Debian prerelease) (Debian testing/unstable)
>Environment:
System: Linux shiva 2.4.20-ac2 #1 Sun Jan 5 10:47:07 CET 2003 i686
unknown unknown GNU/Linux
Architecture: i686

	
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared
--with-system-zlib --enable-nls --without-included-gettext
--enable-__cxa_atexit --enable-clocale=gnu --enable-debug
--enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc
i386-linux
>Description:
g++ 3.3 treats members of a union as if they were of the
first member's type. g++ 3.2 and gcc 3.3 can compile it.
>How-To-Repeat:
struct a {
        int x;
};

struct b {
	int x;
        int y;
};

struct foo {
        union {
		struct a a;
		struct b b;
	} u;
};

int main(void)
{
	struct foo bar = { u: { b: { x: 0, y: 0, }}};
	(void)bar;
	return 0;
}

$ CXXFLAGS="" CPPFLAGS="" g++-3.3 union_bug.cpp -o union_bug
union_bug.cpp: In function `int main()':
union_bug.cpp:20: error: too many initializers for `a'

>Fix:
	






Reply to: