This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/68113] VLA+typeof+new -- confusing warning
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 28 Nov 2015 00:34:24 +0000
- Subject: [Bug c++/68113] VLA+typeof+new -- confusing warning
- Auto-submitted: auto-generated
- References: <bug-68113-4 at http dot gcc dot gnu dot org/bugzilla/>
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.