[Bug c++/50169] "new struct X {{}};" incorrectly treated as an invalid struct-definition
egallager at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Aug 18 13:50:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50169
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |egallager at gcc dot gnu.org
--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Johannes Schaub from comment #0)
> The following looks like valid code:
>
> struct A { int a; };
> int main() {
> new struct A {{ }};
> }
>
> The type-specifier-seq "struct A" is followed by a braced-init-list "{{}}".
> But GCC says:
>
> main1.cpp: In function 'int main()':
> main1.cpp:3:16: error: types may not be defined in a new-type-id
> main1.cpp:3:17: error: expected unqualified-id before '{' token
>
> As far as I can see, I would only define a new type if I would say:
>
> new struct A { };
>
> But the two-braces disambiguates it.
Confirmed that g++ rejects it, but clang++ rejects it too:
$ /usr/local/bin/g++ -c -Wall -Wextra -pedantic 50169.cc
50169.cc: In function ‘int main()’:
50169.cc:3:15: error: types may not be defined in a new-type-id
new struct A {{ }};
^
50169.cc:3:16: error: expected unqualified-id before ‘{’ token
new struct A {{ }};
^
$ /sw/opt/llvm-3.1/bin/clang++ -c -Wall -Wextra -pedantic 50169.cc
50169.cc:3:16: error: expected member name or ';' after declaration specifiers
new struct A {{ }};
^
50169.cc:3:13: error: 'A' can not be defined in a type specifier
new struct A {{ }};
^
2 errors generated.
$
...so I'm not sure if it's an incorrect treatment or not...
(In reply to Ville Voutilainen from comment #1)
> Trying
>
> struct A { int a; };
> int main() {
> new (struct A) {{ }};
> }
>
> gives
>
> internal compiler error: in cxx_eval_bare_aggregate, at cp/semantics.c:6601
>
I can't reproduce this ICE with gcc8...
I guess I'll leave this in UNCONFIRMED for now.
More information about the Gcc-bugs
mailing list