public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/40076] g++ should not permit types to be defined in compound literals
[not found] <bug-40076-4@http.gcc.gnu.org/bugzilla/>
@ 2012-05-02 20:04 ` manu at gcc dot gnu.org
2012-05-02 20:14 ` joseph at codesourcery dot com
2012-05-02 20:21 ` manu at gcc dot gnu.org
2 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2012-05-02 20:04 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40076
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2012-05-02
CC| |manu at gcc dot gnu.org
Ever Confirmed|0 |1
--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-05-02 20:04:08 UTC ---
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++.
GCC prints:
pr40076.cc:1:17: error: initializer element is not constant
int i = (struct s3 { int j; }) { 1 }.j;
^
which is less clear.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/40076] g++ should not permit types to be defined in compound literals
[not found] <bug-40076-4@http.gcc.gnu.org/bugzilla/>
2012-05-02 20:04 ` [Bug c++/40076] g++ should not permit types to be defined in compound literals manu at gcc dot gnu.org
@ 2012-05-02 20:14 ` joseph at codesourcery dot com
2012-05-02 20:21 ` manu at gcc dot gnu.org
2 siblings, 0 replies; 6+ messages in thread
From: joseph at codesourcery dot com @ 2012-05-02 20:14 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/40076] g++ should not permit types to be defined in compound literals
[not found] <bug-40076-4@http.gcc.gnu.org/bugzilla/>
2012-05-02 20:04 ` [Bug c++/40076] g++ should not permit types to be defined in compound literals manu at gcc dot gnu.org
2012-05-02 20:14 ` joseph at codesourcery dot com
@ 2012-05-02 20:21 ` manu at gcc dot gnu.org
2 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2012-05-02 20:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40076
--- Comment #6 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-05-02 20:20:53 UTC ---
(In reply to comment #5)
> That's correct for C++ (by the analogy discussed in this bug report), but
> not for C.
My fault. Clang pays more attention to the file extension than to the driver
used. The correct output for C is:
test.c:1:9: error: initializer element is not a compile-time constant
int i = (struct s3 { int j; }) { 1 }.j;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated
which makes the error clearer than in gcc because of the caret location and the
range (plus the beautiful colors ;-).
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/40076] g++ should not permit types to be defined in compound literals
2009-05-08 21:36 [Bug c++/40076] New: " ian at airs dot com
2009-05-08 21:42 ` [Bug c++/40076] " pinskia at gcc dot gnu dot org
2009-05-08 21:51 ` pinskia at gcc dot gnu dot org
@ 2009-05-08 22:19 ` ian at airs dot com
2 siblings, 0 replies; 6+ messages in thread
From: ian at airs dot com @ 2009-05-08 22:19 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from ian at airs dot com 2009-05-08 22:19 -------
Yeah, in C you can define a struct type in a type cast and then use it later.
Cool stuff.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40076
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/40076] g++ should not permit types to be defined in compound literals
2009-05-08 21:36 [Bug c++/40076] New: " ian at airs dot com
2009-05-08 21:42 ` [Bug c++/40076] " pinskia at gcc dot gnu dot org
@ 2009-05-08 21:51 ` pinskia at gcc dot gnu dot org
2009-05-08 22:19 ` ian at airs dot com
2 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-05-08 21:51 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2009-05-08 21:51 -------
Oh, types are valid to be defined in casts in C. You did not mention that in
the bug report so I thought you could not define a type in C either.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40076
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/40076] g++ should not permit types to be defined in compound literals
2009-05-08 21:36 [Bug c++/40076] New: " ian at airs dot com
@ 2009-05-08 21:42 ` pinskia at gcc dot gnu dot org
2009-05-08 21:51 ` pinskia at gcc dot gnu dot org
2009-05-08 22:19 ` ian at airs dot com
2 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-05-08 21:42 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2009-05-08 21:41 -------
But is defining a new type in a compound literal legal for C99?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40076
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-05-02 20:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-40076-4@http.gcc.gnu.org/bugzilla/>
2012-05-02 20:04 ` [Bug c++/40076] g++ should not permit types to be defined in compound literals manu at gcc dot gnu.org
2012-05-02 20:14 ` joseph at codesourcery dot com
2012-05-02 20:21 ` manu at gcc dot gnu.org
2009-05-08 21:36 [Bug c++/40076] New: " ian at airs dot com
2009-05-08 21:42 ` [Bug c++/40076] " pinskia at gcc dot gnu dot org
2009-05-08 21:51 ` pinskia at gcc dot gnu dot org
2009-05-08 22:19 ` ian at airs dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).