g++ with bad struct initializer. (original) (raw)

Description Kristian Hogsberg 2003-08-08 09:42:39 UTC

g++ crashes with an ICE on the following program:

struct bug { const char *name; unsigned long type; };

struct bug s = { 0, (unsigned long) &s | 1 };

When compiled as C code, gcc says "initializer element is not computable at load time".

Output of gcc -v:

Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux Thread model: posix gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

Comment 1 Drea Pinski 2003-08-08 12:08:08 UTC

It did not crash on 2.95.3 (and was accepted). I can confirm this in 3.3.1 (20030707) and the mainline (20030807). Even 2.97 20001231 crash (according to Phil's regression hunter) and 2.96 (20000731 RedHat) crashes.

Comment 2 Falk Hueffner 2003-08-08 14:37:53 UTC

This is really ice-on-invalid-code, since a constant expression may contain addresses only with constant offsets. I can't reproduce the ICE with mainline 20030802 on alphaev68-unknown-linux-gnu.

Comment 3 Drea Pinski 2003-08-08 15:51:57 UTC

Actually it is valid as in C++ you can have initializers which are not constant. I also can confirm this on powerpc-apple-darwin6.6 on the mainline (20030806).

Comment 6 Mark Mitchell 2003-09-07 23:52:21 UTC

Fixed in GCC 3.3.2, GCC 3.4.