https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68531
Bug ID: 68531 Summary: incorrect code for VLA in C++ 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: --- G++ accepts variable length arrays as an extension but generates the wrong code for some basic uses cases of such arrays: it allows changes in the value of a variable that determines the number of elements in a VLA type to affect the bound of the VLA after it has been defined. When compiled with gcc (in C mode), or by Clang in either C or C++ modes, the following program compiles and runs successfully to completion. However, when compiled with g++, either today's trunk or as far back as 4.5.3 (the oldest I tested), it aborts. $ cat x.c && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -Wall -Wextra -Wpedantic -xc++ x.c && ./a.out int main () { int nelems = 7; typedef char A [nelems]; nelems = 2; A a; if (sizeof (A) != 7 || sizeof a != 7) __builtin_abort (); } x.c: In function ‘int main()’: x.c:5:27: warning: ISO C++ forbids variable length array ‘A’ [-Wvla] typedef char A [nelems]; ^ Aborted (core dumped)