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)
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.
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.
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).
Subject: Bug 11852 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2003-09-07 23:48:34 Modified files: gcc : varasm.c ChangeLog gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/init: struct1.C Log message: PR c++/11852 * varasm.c (initializer_constant_valid_p): Correct logic for CONSTRUCTORs. PR c++/11852 * g++.dg/init/struct1.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/varasm.c.diff?cvsroot=gcc&r1=1.381&r2=1.382 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.1000&r2=2.1001 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3035&r2=1.3036 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/struct1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 11852 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: mmitchel@gcc.gnu.org 2003-09-07 23:51:05 Modified files: gcc : varasm.c ChangeLog gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/init: struct1.C Log message: PR c++/11852 * varasm.c (initializer_constant_valid_p): Correct logic for CONSTRUCTORs. PR c++/11852 * g++.dg/init/struct1.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/varasm.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.324.2.7&r2=1.324.2.8 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.728&r2=1.16114.2.729 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.271&r2=1.2261.2.272 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/struct1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
Fixed in GCC 3.3.2, GCC 3.4.