[no subject]
>Submitter-Id: net
>Originator: BAN Nobuhiro
>Organization:
>Confidential: no
>Synopsis: [3.3/3.4] ICE on initializer with an array index
>Severity: non-critical
>Priority: medium
>Category: c++
>Class: ice-on-illegal-code
>Release: 3.3.2 20030908 (Debian prerelease) (Debian testing/unstable) et al.
>Environment:
(a) Debian GNU/Linux testing (GCC version 3.3.2 20030908 (Debian prerelease))
and
(b) FreeBSD 5.1-CURRENT (GCC version 3.3.1)
and
(c) FreeBSD 4.8 (GCC 3.4 cvs at 2003/10/07 (JST))
* More information about (a):
Packages: (result from `dpkg -l g++ g++-3.3')
ii g++ 3.3.1-2 The GNU C++ compiler.
ii g++-3.3 3.3.2-0pre4 The GNU C++ compiler
Architecture: i686
host: i486-pc-linux-gnu
build: i486-pc-linux-gnu
target: i486-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 i486-linux
Thread model: posix
gcc version 3.3.2 20030908 (Debian prerelease)
* More information about (b):
% uname -a
FreeBSD sto.ipl.t.u-tokyo.ac.jp 5.1-CURRENT FreeBSD 5.1-CURRENT #3: Wed Oct 1 19:30:06 JST 2003 root@sto.ipl.t.u-tokyo.ac.jp:/work/src/sys/i386/compile/STO i386
% gcc -v
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.3.1 [FreeBSD]
* More information about (c):
% gcc -v
Using built-in specs.
Configured with: ./configure --enable-languages=c++,c
Thread model: posix
gcc version 3.4 20031006 (experimental)
>Description:
A declaration of an array with an array index causes an ICE on 3.3/3.4.
When C++ parser calls build_tree_list() (or tree_cons()) with
PURPOSE parameter, this function makes a TREE node which TREE_PURPOSE is
non-NULL. Then reshape_init()'s array initializer processing routine
passes its PURPOSE to size_binop(), which causes type mismatch and an ICE.
>How-To-Repeat:
To compile these files:
---- ice1.ii
int a[] = { [1] 1 };
---- ice2.ii
enum { FOO = 1, BAR = 2 };
int a[] = { FOO: 1, BAR: 2 };
---- ice3.ii
int a[] = { FOO: 1, BAR: 2 };
---- end
ice1.ii is GCC's old-style C-extention code, and ice2.ii and ice3.ii
are both invalid code.
LOG:
% g++ ice1.ii
ice1.ii:1: internal compiler error: in size_binop, at fold-const.c:1459
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
% g++ ice2.ii
ice2.ii:2: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
% g++ ice3.ii
ice3.ii:1: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
>Fix:
This patch avoids the ICE:
--- gcc/cp/decl.c.old 2003-09-02 15:03:24.000000000 +0900
+++ gcc/cp/decl.c 2003-10-11 03:52:11.000000000 +0900
@@ -8364,7 +8364,10 @@
TREE_CHAIN (element_init) = CONSTRUCTOR_ELTS (new_init);
CONSTRUCTOR_ELTS (new_init) = element_init;
if (TREE_PURPOSE (element_init))
- index = TREE_PURPOSE (element_init);
+ {
+ /* index = TREE_PURPOSE (element_init); */
+ sorry ("initializer with an array index");
+ }
}
}
else
More constructive solution would be to port C's code (and parser)
to C++. It handles a C-extention of designated initializers
much better.
Reply to: