Compiling this invalid C++ code with current mainline: void foo() { static int c = 2; static const char *a[][c] = { { "1", "2" } }; } gives me: foo.cc: In function ‘void foo()’: foo.cc:1: internal compiler error: in tree_low_cst, at tree.c:4519 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions. It should instead say something along the lines of foo.cc:1: error: array bound is not an integer constant
*** Bug 29257 has been marked as a duplicate of this bug. ***
Confirmed. This actually worked in gcc2.95 to my surprise: g/x> /home/bangerth/bin/gcc-2.95.3/bin/c++ -c x.cc x.cc: In function `void foo()': x.cc:1: variable-sized object of type `const char *[((c - 1) + 1)]' may not be initialized x.cc:1: storage size of `a' isn't constant All later gcc versions ICE, however. W.
Shorter testcase (the array doesn't have to be static): ========================= void foo(int i) { int x[][i] = { 0 }; } ========================= The bug appeared with GCC 3.3.
Subject: Bug 29175 Author: mmitchel Date: Thu Oct 12 04:35:56 2006 New Revision: 117658 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117658 Log: PR c++/29175 * decl.c (check_initializer): Issue errors about trying to initialize arrays whose elements have variable size. PR c++/29175 * g++.dg/init/array24.C: New test. Added: trunk/gcc/testsuite/g++.dg/init/array24.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c trunk/gcc/testsuite/ChangeLog
Fixed in 4.2.0.
Subject: Bug 29175 Author: mmitchel Date: Thu Oct 12 23:53:04 2006 New Revision: 117677 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117677 Log: PR c++/29175 * decl.c (check_initializer): Issue errors about trying to initialize arrays whose elements have variable size. PR c++/29175 * g++.dg/init/array24.C: New test. Added: branches/gcc-4_1-branch/gcc/testsuite/g++.dg/init/array24.C Modified: branches/gcc-4_1-branch/gcc/cp/ChangeLog branches/gcc-4_1-branch/gcc/cp/decl.c branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
Fixed in GCC-4.1.2