Current GCC trunk (6.0) as well as 5.1.0 loops indefinitely compiling the following quasi-legal C++ 11 code (loosely based on bug 69496). Clang rejects the code because it doesn't accept initialized VLAs. The same code compiles successfully with -Dconstexpr=''. $ (cat t.c && ulimit -t 10 && /home/msebor/build/gcc-trunk-svn/gcc/xgcc -B/home/msebor/build/gcc-trunk-svn/gcc -S -Wall -Wextra -Wpedantic -std=c++14 -xc++ t.c) constexpr int foo (int n) { int a [n] = { 0 }; int z = a [0] + (n ? foo (n - 1) : 0); return z; } constexpr int i = foo (3); t.c: In function ‘constexpr int foo(int)’: t.c:3:13: warning: ISO C++ forbids variable length array ‘a’ [-Wvla] int a [n] = { 0 }; ^ xgcc: internal compiler error: Killed (program cc1plus) Please submit a full bug report, with preprocessed source if appropriate. See <http://gcc.gnu.org/bugs.html> for instructions.
Confirmed.
Marking this a 5/6 regression since ICE 4.9.3 rejects the code with the error below because it doesn't allow contexpr functions to have more than one (return) statement. t.c: In function ‘constexpr int foo(int)’: t.c:8:1: error: body of constexpr function ‘constexpr int foo(int)’ not a return-statement } ^ t.c: At global scope: t.c:10:25: error: ‘constexpr int foo(int)’ called in a constant expression constexpr int i = foo (3); ^
I see the problem here too.
Author: mpolacek Date: Fri Jan 29 09:25:14 2016 New Revision: 232969 URL: https://gcc.gnu.org/viewcvs?rev=232969&root=gcc&view=rev Log: PR c++/69509 PR c++/69516 * constexpr.c (cxx_eval_array_reference): Give the "array subscript out of bound" error earlier. * init.c (build_vec_init): Change NE_EXPR into GT_EXPR. Update the commentary. * g++.dg/ext/constexpr-vla2.C: New test. * g++.dg/ext/constexpr-vla3.C: New test. * g++.dg/ubsan/vla-1.C: Remove dg-shouldfail. Added: trunk/gcc/testsuite/g++.dg/ext/constexpr-vla2.C trunk/gcc/testsuite/g++.dg/ext/constexpr-vla3.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/constexpr.c trunk/gcc/cp/init.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.dg/ubsan/vla-1.C
Fixed for GCC 6.