https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91506
Bug ID: 91506 Summary: Incorrectly issued error: parameter may not have variably modified type Product: gcc Version: 9.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: abbeyj+gcc at gmail dot com Target Milestone: --- Compiling: double test(int *arr, int x) { double ret(double(arr[x]) + 1); return ret; } produces: <source>: In function 'double test(int*, int)': <source>:2:23: error: parameter may not have variably modified type 'double [x]' 2 | double ret(double(arr[x]) + 1); | ^~~ It looks like this could be a Most Vexing Parse situation but clang, ICC and MSVC accept it. GCC accepts this similar code which doesn't seem like it should be treated differently from the above: double test(int *arr, int x) { int y = x; double ret(double(arr[y]) + 1); return ret; } Compiling with -std=c++03 changes things so GCC accepts the testcase. Compiling with -Wvla gets you an additional warning: <source>:2:23: warning: variable length array 'arr' is used [-Wvla] 2 | double ret(double(arr[x]) + 1); | ^~~ This makes it seem like GCC is parsing this as a function declaration. But after the error is issued GCC ends up treating `ret` as having type `double`, not as a function; changing the code to something like `return ret.foo();` produces an error saying `... 'ret', which is of non-class type 'double'`. Testing on godbolt.org shows that this is reproducible all the way back to 4.6.4 (if using `-std=c++0x`). Version 4.5.3 does not exhibit the problem. Possibly related to bug 41786 ?