This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/40076] g++ should not permit types to be defined in compound literals
- From: "joseph at codesourcery dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 02 May 2012 20:13:02 +0000
- Subject: [Bug c++/40076] g++ should not permit types to be defined in compound literals
- Auto-submitted: auto-generated
- References: <bug-40076-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40076
--- Comment #5 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2012-05-02 20:13:02 UTC ---
On Wed, 2 May 2012, manu at gcc dot gnu.org wrote:
> I think this is confirmed. Clang prints:
>
> pr40076.cc:1:17: error: 's3' can not be defined in a type specifier
> int i = (struct s3 { int j; }) { 1 }.j;
> ^
> 1 error generated.
>
> for both C and C++.
That's correct for C++ (by the analogy discussed in this bug report), but
not for C.
> pr40076.cc:1:17: error: initializer element is not constant
> int i = (struct s3 { int j; }) { 1 }.j;
> ^
>
> which is less clear.
That's a correct error for C, however; C allows types to be defined like
that in sizeof, casts and compound literals, but that initializer is not
(required to be) constant in C standard terms.