C++11 with GNU VLA extention results in ICE
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gcc-7 (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
I have just encountered an "internal compiler error" while using gcc-7.
```cpp source code
#include <cstdio>
int main()
{
int N = 100;
int K = 100;
int dp[N][2][K] = {0};
printf("%d\n", dp[0][0][0]);
return 0;
}
```
After executing
g++ test.cc
Output is
test.cc: In function ‘int main()’:
test.cc:7:25: internal compiler error: in make_decl_rtl, at varasm.c:1310
int dp[N][2][K] = {0};
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:/
which is exectly same with these three options: "-std=c++11", "-std=c++14", "-std=c++17".
With executing
g++ test.cc -std=c++98
the binary is produced normally.
With executing
g++ test.cc -std=c++98 -ansi -pedantic -Wextra -Werror
Output is
test.cc: In function ‘int main()’:
test.cc:7:19: error: ISO C++ forbids variable length array ‘dp’ [-Werror=vla]
int dp[N][2][K] = {0};
test.cc:7:19: error: ISO C++ forbids variable length array ‘dp’ [-Werror=vla]
cc1plus: all warnings being treated as errors
which is expected.
According to my observation, this seems to be the issue related to the order of 'N','2','K',
if I write
int dp[N][K][2] = {0};
then everything is fine.
Here is my gcc version (gcc -v):
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_
OFFLOAD_
OFFLOAD_
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-
Thread model: posix
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~
BTW, the preprocessed file 'test.ii' can be found in the 'Attachment' in case you need it.