[Bug c++/40076] g++ should not permit types to be defined in compound literals

2012-05-02 Thread manu at gcc dot gnu.org
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.


[Bug c++/40076] g++ should not permit types to be defined in compound literals

2012-05-02 Thread joseph at codesourcery dot com
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.


[Bug c++/40076] g++ should not permit types to be defined in compound literals

2012-05-02 Thread manu at gcc dot gnu.org
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 ;-).


[Bug c++/40076] g++ should not permit types to be defined in compound literals

2009-05-08 Thread pinskia at gcc dot gnu dot org


--- 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



[Bug c++/40076] g++ should not permit types to be defined in compound literals

2009-05-08 Thread pinskia at gcc dot gnu dot org


--- 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



[Bug c++/40076] g++ should not permit types to be defined in compound literals

2009-05-08 Thread ian at airs dot com


--- 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