Bug 29175 - [4.0 regression] ICE on invalid C++ variable length array
Summary: [4.0 regression] ICE on invalid C++ variable length array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P2 normal
Target Milestone: 4.1.2
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code, monitored
: 29257 (view as bug list)
Depends on:
Blocks: C++VLA
  Show dependency treegraph
 
Reported: 2006-09-21 21:35 UTC by Ian Lance Taylor
Modified: 2007-02-03 20:20 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work: 2.95 3.0.4 3.2.3
Known to fail: 3.3 3.4.6 4.0.3 4.1.1 4.2.0
Last reconfirmed: 2006-09-28 05:59:32


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Lance Taylor 2006-09-21 21:35:14 UTC
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
Comment 1 Andrew Pinski 2006-09-28 01:18:11 UTC
*** Bug 29257 has been marked as a duplicate of this bug. ***
Comment 2 Wolfgang Bangerth 2006-09-28 05:59:32 UTC
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.
Comment 3 Volker Reichelt 2006-10-08 20:29:43 UTC
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.
Comment 4 Mark Mitchell 2006-10-12 04:36:07 UTC
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

Comment 5 Mark Mitchell 2006-10-12 04:39:56 UTC
Fixed in 4.2.0.
Comment 6 Mark Mitchell 2006-10-12 23:53:14 UTC
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

Comment 7 Gabriel Dos Reis 2007-02-03 20:20:49 UTC
Fixed in GCC-4.1.2