https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69517
Bug ID: 69517
Summary: [5/6 regression] SEGV on a VLA with excess initializer
elements
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
Continuing with my testing of VLAs in G++ (see bug 69516, bug 69496, and bug
69509), I discovered another problem.
When compiled with GCC 4.9.3, the program below aborts with the following
output:
terminate called after throwing an instance of 'std::bad_array_length'
what(): std::bad_array_length
Aborted (core dumped)
However, when compiled with 5.x or 6.0, it crashes with a SEGV:
$ (cat t.c && ulimit -t 10 && ~/bin/gcc-5.1.0/bin/g++ -Wall -Wextra -Wpedantic
-std=c++14 -xc++ t.c) && ./a.out
int foo (int n)
{
int a[n] = { 1, 2, 3, 4, 5, 6 };
int z = 0;
for (unsigned i = 0; i < 3; ++i)
z += a[i];
return z;
}
int main ()
{
int n = foo (3);
__builtin_printf ("%d\n", n);
}
t.c: In function ‘int foo(int)’:
t.c:3:13: warning: ISO C++ forbids variable length array ‘a’ [-Wvla]
int a[n] = { 1, 2, 3, 4, 5, 6 };
^
Segmentation fault (core dumped)