https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68113
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2015-11-28
CC| |msebor at gcc dot gnu.org
Ever confirmed|0 |1
Known to fail| |5.2.0, 6.0
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed with decltype instead of __typeof__. The 'new decltype(a)' construct
is valid provided a is not a VLA. The strange warning message is caused by gcc
not distinguishing 'new (int[n])' (a GCC extension) from 'new decltype(a)' in
the function that issues the warning (build_new_1 in cp/init.c).
$ cat x.cpp && /build/gcc-trunk-svn/gcc/xg++ -B /build/gcc-trunk-svn/gcc -S
-Wall -Wextra -Wpedantic -std=c++11 x.cpp
int main ()
{
int n = 1;
int a [n];
new decltype (a);
}
x.cpp: In function ‘int main()’:
x.cpp:4:13: warning: ISO C++ forbids variable length array ‘a’ [-Wvla]
int a [n];
^
x.cpp:5:9: warning: non-constant array new length must be specified without
parentheses around the type-id [-Wvla]
new decltype (a);
^~~~~~~~
Clang rejects the code because it doesn't allow VLAs in new expressions:
$ /build/llvm-trunk/bin/clang++ -Wall -Wextra -std=c++11 x.cpp
x.cpp:5:9: error: 'new' cannot allocate object of variably modified type
'decltype(a)' (aka 'int [n]')
new decltype (a);
^
1 error generated.