https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70075
Bug ID: 70075 Summary: incorrect initialization of multidimensional VLAs 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: --- Unlike GCC in C mode, G++ accepts explicitly initialized variable length arrays (as specified in WG21 N3639, http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3639.html). However, when initializing VLAs with more elements than explicitly specified in the initializer, G++ fails to zero-initialize the remaining elements as would be the case for ordinary arrays. The following test case demonstrates the problem: cat z.cpp && /build/gcc-trunk/gcc/xgcc -B /build/gcc-trunk/gcc -Wall -Wextra -Wpedantic z.cpp && ./a.out void __attribute__ ((noclone, noinline)) bar (int n) { const int m = 2; char a [m][n] = { { 0, 1, 2 } }; for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) __builtin_printf ("%hhi ", a [i][j]); __builtin_printf ("\n"); if (a [0][n - 1] != 0) __builtin_abort (); } int main () { bar (4); } z.cpp: In function ‘void bar(int)’: z.cpp:4:15: warning: ISO C++ forbids variable length array ‘a’ [-Wvla] char a [m][n] = { { 0, 1, 2 } }; ^ 0 1 2 12 -1 127 0 0 Aborted (core dumped)